-
Notifications
You must be signed in to change notification settings - Fork 17
Feature/init sample #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
665b94d
97e9c68
295ef2e
c9cf7c2
42b8a9f
f80f860
282b4aa
3c73a92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| apply plugin: 'com.android.application' | ||
|
|
||
| android { | ||
| compileSdkVersion 25 | ||
| buildToolsVersion "25.0.0" | ||
| defaultConfig { | ||
| applicationId "sk.inloop.support" | ||
| minSdkVersion 15 | ||
| targetSdkVersion 25 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| compile fileTree(dir: 'libs', include: ['*.jar']) | ||
| androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
| exclude group: 'com.android.support', module: 'support-annotations' | ||
| }) | ||
| compile 'com.android.support:appcompat-v7:25.0.1' | ||
| testCompile 'junit:junit:4.12' | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # By default, the flags in this file are appended to flags specified | ||
| # in /Users/adammihalik/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
| # You can edit the include path and order by changing the proguardFiles | ||
| # directive in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # Add any project specific keep options here: | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package sk.inloop.support.sample; | ||
|
|
||
| import android.content.Context; | ||
| import android.support.test.InstrumentationRegistry; | ||
| import android.support.test.runner.AndroidJUnit4; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| /** | ||
| * Instrumentation test, which will execute on an Android device. | ||
| * | ||
| * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
| */ | ||
| @RunWith(AndroidJUnit4.class) | ||
| public class ExampleInstrumentedTest { | ||
| @Test | ||
| public void useAppContext() throws Exception { | ||
| // Context of the app under test. | ||
| Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
|
||
| assertEquals("sk.inloop.support.sample", appContext.getPackageName()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="sk.inloop.support.sample"> | ||
|
|
||
| <application | ||
| android:allowBackup="true" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/AppTheme"> | ||
| <activity | ||
| android:name=".IncorrectMainActivity" | ||
| android:label="@string/fail_activity_name" | ||
| android:theme="@style/AppTheme.NoActionBar"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
|
|
||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity | ||
| android:name=".FixedMainActivity" | ||
| android:label="@string/fixed_activity_name" | ||
| android:theme="@style/AppTheme.NoActionBar"> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package sk.inloop.support.sample; | ||
|
|
||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.support.v4.view.ViewPager; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.support.v7.widget.Toolbar; | ||
| import android.view.Menu; | ||
| import android.view.View; | ||
| import android.widget.Button; | ||
|
|
||
| import sk.inloop.support.sample.adapter.CorrectFragmentAdapter; | ||
|
|
||
| public class FixedMainActivity extends AppCompatActivity { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should separate these "test" activities into a separate module - so that it's not part of the library .aar. |
||
|
|
||
| private CorrectFragmentAdapter mSectionsPagerAdapter; | ||
|
|
||
| private ViewPager mViewPager; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
|
|
||
| Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); | ||
| setSupportActionBar(myToolbar); | ||
|
|
||
| mSectionsPagerAdapter = new CorrectFragmentAdapter(getSupportFragmentManager()); | ||
|
|
||
| mViewPager = (ViewPager) findViewById(R.id.container); | ||
| mViewPager.setAdapter(mSectionsPagerAdapter); | ||
|
|
||
| ((Button)findViewById(R.id.test_start_btn)).setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| mSectionsPagerAdapter.toggleState(); | ||
| } | ||
| }); | ||
|
|
||
| ((Button)findViewById(R.id.switch_tests_btn)).setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| Intent intent = new Intent(FixedMainActivity.this, IncorrectMainActivity.class); | ||
| intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
| FixedMainActivity.this.startActivity(intent); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public boolean onCreateOptionsMenu(Menu menu) { | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package sk.inloop.support.sample; | ||
|
|
||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.support.v4.view.ViewPager; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.support.v7.widget.Toolbar; | ||
| import android.view.Menu; | ||
| import android.view.View; | ||
| import android.widget.Button; | ||
|
|
||
| import sk.inloop.support.sample.adapter.IncorrectFragmentAdapter; | ||
|
|
||
| public class IncorrectMainActivity extends AppCompatActivity { | ||
|
|
||
| private IncorrectFragmentAdapter mSectionsPagerAdapter; | ||
|
|
||
| private ViewPager mViewPager; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
|
|
||
| Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); | ||
| setSupportActionBar(myToolbar); | ||
|
|
||
| mSectionsPagerAdapter = new IncorrectFragmentAdapter(getSupportFragmentManager()); | ||
|
|
||
| mViewPager = (ViewPager) findViewById(R.id.container); | ||
| mViewPager.setAdapter(mSectionsPagerAdapter); | ||
|
|
||
| ((Button)findViewById(R.id.test_start_btn)).setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| mSectionsPagerAdapter.toggleState(); | ||
| } | ||
| }); | ||
|
|
||
| ((Button)findViewById(R.id.switch_tests_btn)).setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| Intent intent = new Intent(IncorrectMainActivity.this, FixedMainActivity.class); | ||
| intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||
| IncorrectMainActivity.this.startActivity(intent); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public boolean onCreateOptionsMenu(Menu menu) { | ||
| return true; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package sk.inloop.support.sample; | ||
|
|
||
| import android.os.Bundle; | ||
| import android.support.annotation.Nullable; | ||
| import android.support.v4.app.Fragment; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.TextView; | ||
|
|
||
| /** | ||
| * Created by adammihalik on 05/12/2016. | ||
| */ | ||
|
|
||
| public class SampleFragment extends Fragment { | ||
| public static SampleFragment newInstance(String label) { | ||
| Bundle bundle = new Bundle(); | ||
| bundle.putString("label", label); | ||
| SampleFragment testFragment = new SampleFragment(); | ||
| testFragment.setArguments(bundle); | ||
| return testFragment; | ||
| } | ||
|
|
||
| public String getLabel() { | ||
| return getArguments().getString("label"); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| return inflater.inflate(R.layout.fragment_template, container, false); | ||
| } | ||
|
|
||
| @Override | ||
| public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| ((TextView)view.findViewById(R.id.fragment_label)).setText(getLabel()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package sk.inloop.support.sample.adapter; | ||
|
|
||
| import android.support.v4.app.Fragment; | ||
| import android.support.v4.app.FragmentManager; | ||
|
|
||
| import sk.inloop.support.sample.SampleFragment; | ||
| import sk.inloop.support.v4.app.FragmentStatePagerAdapter; | ||
|
|
||
| /** | ||
| * Extends {@link sk.inloop.support.v4.app.FragmentStatePagerAdapter}, therefore {@link #notifyDataSetChanged()} will not fail. | ||
| */ | ||
| public class CorrectFragmentAdapter extends FragmentStatePagerAdapter { | ||
|
|
||
| private boolean mState = true; | ||
|
|
||
| public CorrectFragmentAdapter(FragmentManager fragmentManager) { | ||
| super(fragmentManager); | ||
| } | ||
|
|
||
| @Override | ||
| public int getCount() { | ||
| return 3; | ||
| } | ||
|
|
||
| public void toggleState() { | ||
| mState = !mState; | ||
| notifyDataSetChanged(); | ||
| } | ||
|
|
||
| private String getLabel(int position) { | ||
| switch (position) { | ||
| case 0: | ||
| return "A"; | ||
| case 1: | ||
| return mState ? "B" : "C"; | ||
| default: | ||
| return mState ? "C" : "B"; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int getItemPosition(Object object) { | ||
| String label = ((SampleFragment) object).getLabel(); | ||
| if (label.equals("A")) { | ||
| return 0; | ||
| } else if (label.equals("B")) { | ||
| return mState ? 1 : 2; | ||
| } else { | ||
| return mState ? 2 : 1; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CharSequence getPageTitle(int position) { | ||
| return getLabel(position); | ||
| } | ||
|
|
||
| @Override | ||
| public Fragment getItem(int position) { | ||
| return SampleFragment.newInstance(getLabel(position)); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using "eu.inloop....."