Skip to content

Commit

Permalink
practicing view pager with imageview
Browse files Browse the repository at this point in the history
  • Loading branch information
moisesaq committed Apr 13, 2016
1 parent 16c0618 commit 1dd3f06
Show file tree
Hide file tree
Showing 18 changed files with 447 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/me.relex/circleindicator/1.1.8/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
Expand All @@ -92,9 +93,11 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="circleindicator-1.1.8" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.0" level="project" />
<orderEntry type="library" exported="" name="design-23.1.0" level="project" />
<orderEntry type="library" exported="" name="greendao-2.1.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
Expand Down
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.apaza.moises.practicegreendao"
minSdkVersion 11
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
Expand All @@ -26,4 +26,10 @@ dependencies {
compile 'com.android.support:design:23.1.0'

compile 'de.greenrobot:greendao:2.1.0'

//LOAD IMAGE
compile 'com.github.bumptech.glide:glide:3.6.0'

//View pager indicator
compile 'me.relex:circleindicator:1.1.8@aar'
}
24 changes: 22 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.apaza.moises.practicegreendao" >

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<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=".MainActivity"
android:label="@string/app_name"
android:name=".login.SplashActivity"
android:label="@string/title_activity_splash"
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=".login.SignUpActivity"
android:label="@string/title_activity_signup"
android:theme="@style/AppTheme.NoActionBar" >
</activity>

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
</activity>


</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ private void setup(){
public void onClick(View v) {
try{
if(v.getId() == register.getId()){
userDao.insert(getNewUserOfView());
placeDao.insert(getNewPlaceOfView());
long userId = userDao.insert(getNewUserOfView());
placeDao.insert(getNewPlaceOfView(userId));
}
}catch (Exception e){
e.printStackTrace();
}
}

public Place getNewPlaceOfView(){
public Place getNewPlaceOfView(long userId){
Place place = new Place();
place.setName(etName.getText().toString());
place.setAddress(etAddress.getText().toString());
place.setDescription(etDescription.getText().toString());
place.setUser(getNewUserOfView());
place.setUserId(userId);

return place;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.apaza.moises.practicegreendao.login;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.apaza.moises.practicegreendao.R;

public class SignUpActivity extends AppCompatActivity implements SignUpFragment.OnFragmentSignUpListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

toolbar.setVisibility(View.GONE);
showFragment(SignUpFragment.newInstance());

/*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();
}
});*/

}

public void showFragment(Fragment fragment){
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(fragment.getClass().getSimpleName());
ft.replace(R.id.containerSignUp, fragment);
ft.commit();
}

@Override
public void onSignUpClick() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.apaza.moises.practicegreendao.login;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.apaza.moises.practicegreendao.R;
import com.bumptech.glide.Glide;

import me.relex.circleindicator.CircleIndicator;

public class SignUpFragment extends Fragment {

private static final String ARG_PARAM1 = "param1";
private String mParam1;

private View view;
private ViewPager viewPager;
private Button btnSignUp;

private ImagePageAdapter imagePageAdapter;
private CircleIndicator circleIndicator;

public int[] mResources = {R.drawable.vegeta, R.drawable.goku, R.drawable.buu};

private OnFragmentSignUpListener mListener;

public static SignUpFragment newInstance() {
SignUpFragment fragment = new SignUpFragment();
return fragment;
}

public SignUpFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_sign_up, container, false);
setup();
return view;
}

private void setup(){
viewPager = (ViewPager)view.findViewById(R.id.viewPagerSignUp);
imagePageAdapter = new ImagePageAdapter(getActivity().getApplicationContext());
viewPager.setAdapter(imagePageAdapter);

circleIndicator = (CircleIndicator)view.findViewById(R.id.indicator);
circleIndicator.setViewPager(viewPager);
btnSignUp = (Button) view.findViewById(R.id.signup);
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onSignUpClick();
}
});
}

public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onSignUpClick();
}
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentSignUpListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnFragmentSignUpListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

public interface OnFragmentSignUpListener {
void onSignUpClick();
}

public class ImagePageAdapter extends PagerAdapter{

private Context context;
public ImagePageAdapter(Context context){
this.context = context;
}

@Override
public int getCount() {
return mResources.length;
}

@Override
public boolean isViewFromObject(View view, Object object) {
return (view == (FrameLayout)object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pager_layout, container, false);
ImageView imageView = (ImageView)view.findViewById(R.id.imageView);
//imageView.setImageResource(mResources[position]);
Glide.with(getActivity())
.load(mResources[position])
.centerCrop()
.into(imageView);

container.addView(view);
return view;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((FrameLayout)object);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.apaza.moises.practicegreendao.login;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.apaza.moises.practicegreendao.MainActivity;
import com.apaza.moises.practicegreendao.R;

public class SplashActivity extends AppCompatActivity {

private TextView counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
/*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);*/
counter = (TextView)findViewById(R.id.counter);

startSplash();
}

private void startSplash(){
new CountDownTimer(7000, 1000) {
public void onTick(long millisUntilFinished) {
counter.setText("" + millisUntilFinished / 1000);
}

public void onFinish() {
counter.setText("Go!");
//goToMainActivity();
goToSignUpActivity();
}
}.start();
}

private void goToMainActivity(){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}

private void goToSignUpActivity(){
Intent intent = new Intent(this, SignUpActivity.class);
startActivity(intent);
}
}
Binary file added app/src/main/res/drawable/buu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/goku.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/ic_river_plate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/vegeta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_signup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context="com.apaza.moises.practicegreendao.login.SignUpActivity">

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_signup" />

<!--<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />-->

</android.support.design.widget.CoordinatorLayout>
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/colorPrimary"
tools:context="com.apaza.moises.practicegreendao.login.SplashActivity">

<!--<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>-->

<include layout="@layout/content_splash" />

</android.support.design.widget.CoordinatorLayout>
Loading

0 comments on commit 1dd3f06

Please sign in to comment.