Skip to content

Commit

Permalink
Add fragments
Browse files Browse the repository at this point in the history
Add contact list
  • Loading branch information
CullyCross committed Nov 4, 2015
1 parent ceea1d4 commit 1282c3e
Show file tree
Hide file tree
Showing 25 changed files with 975 additions and 206 deletions.
29 changes: 28 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
}
}

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 23
Expand All @@ -17,11 +28,25 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:design:23.1.0'

compile 'com.squareup.picasso:picasso:2.5.2'

compile 'com.jakewharton:butterknife:7.0.1'
}

retrolambda {
jdk System.getenv("JAVA_HOME")
javaVersion JavaVersion.VERSION_1_7
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.cullycross.test4tabs">

<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".FourTabsActivity"
android:name=".activities.FourTabsActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
Expand Down
152 changes: 0 additions & 152 deletions app/src/main/java/me/cullycross/test4tabs/FourTabsActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package me.cullycross.test4tabs.activities;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import me.cullycross.test4tabs.R;
import me.cullycross.test4tabs.fragments.ContactsFragment;
import me.cullycross.test4tabs.fragments.DatabaseFragment;
import me.cullycross.test4tabs.fragments.PicturesFragment;
import me.cullycross.test4tabs.fragments.SinglePictureFragment;

public class FourTabsActivity extends AppCompatActivity {

private SectionsPagerAdapter mSectionsPagerAdapter;


@Bind(R.id.toolbar) Toolbar mToolbar;
@Bind(R.id.container) ViewPager mViewPager;
@Bind(R.id.tabs) TabLayout mTabLayout;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_four_tabs);
ButterKnife.bind(this);

setSupportActionBar(mToolbar);

mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

mViewPager.setAdapter(mSectionsPagerAdapter);
mTabLayout.setupWithViewPager(mViewPager);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null)
.show();
}
});
}

@Override public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_four_tabs, menu);
return true;
}

@Override public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

public static final String CONTACTS = "Contacts";
public static final String DATABASE = "Database";
public static final String PICTURES = "Pictures";
public static final String SINGLE_PICTURE = "Single picture";

public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override public Fragment getItem(int position) {

switch (position) {
case 0:
return ContactsFragment.newInstance();
case 1:
return DatabaseFragment.newInstance();
case 2:
return PicturesFragment.newInstance();
case 3:
return SinglePictureFragment.newInstance();
default:
return null;
}
}

@Override public int getCount() {
return 4;
}

@Override public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return CONTACTS;
case 1:
return DATABASE;
case 2:
return PICTURES;
case 3:
return SINGLE_PICTURE;
default:
return null;
}
}
}
}
Loading

0 comments on commit 1282c3e

Please sign in to comment.