Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
moinkhan-in committed Apr 25, 2016
0 parents commit 69df84e
Show file tree
Hide file tree
Showing 36 changed files with 753 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1 change: 1 addition & 0 deletions .idea/.name

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

22 changes: 22 additions & 0 deletions .idea/compiler.xml

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

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

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

6 changes: 6 additions & 0 deletions .idea/encodings.xml

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

23 changes: 23 additions & 0 deletions .idea/gradle.xml

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

46 changes: 46 additions & 0 deletions .idea/misc.xml

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

9 changes: 9 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
27 changes: 27 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.msquare.flex_toolbar"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
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 C:\Users\BosLeo3\AppData\Local\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,13 @@
package com.msquare.flex_toolbar;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
20 changes: 20 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msquare.flex_toolbar">

<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
53 changes: 53 additions & 0 deletions app/src/main/java/com/msquare/flex_toolbar/BlankFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.msquare.flex_toolbar;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* Use the {@link BlankFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BlankFragment extends Fragment {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";

private String mTitle;

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

public static BlankFragment newInstance(String title) {
BlankFragment fragment = new BlankFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, title);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mTitle = getArguments().getString(ARG_PARAM1);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_blank, container, false);
((TextView)(v.findViewById(R.id.sample_text))).setText("<" + mTitle + ">");
return v;
}
}
110 changes: 110 additions & 0 deletions app/src/main/java/com/msquare/flex_toolbar/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.msquare.flex_toolbar;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;

public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {

private static final String TAG = "MainActivity";
Toolbar mToolbar;
ViewPager mViewPager;

int heightForPage0 = 150;
int heightForPage1 = 400;
int heightForPage2 = 300;
int heightForPage3 = 600;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mToolbar = (Toolbar) findViewById(R.id.toolBar);
mViewPager = (ViewPager) findViewById(R.id.pager);

mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
setSupportActionBar(mToolbar);

mViewPager.addOnPageChangeListener(this);
mToolbar.setMinimumHeight(heightForPage0);
}

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Log.d(TAG,positionOffset+"");

int currentHeight;
int nextHeight;

switch (position) {
case 0:
currentHeight = heightForPage0;
nextHeight = heightForPage1;
calculateHeightAndApply(currentHeight, nextHeight, positionOffset);
break;
case 1:
currentHeight = heightForPage1;
nextHeight = heightForPage2;
calculateHeightAndApply(currentHeight, nextHeight, positionOffset);
break;
case 2:
currentHeight = heightForPage2;
nextHeight = heightForPage3;
calculateHeightAndApply(currentHeight, nextHeight, positionOffset);
break;
case 3:
// for last page we don't have to worry about it.
// bcoz there is no next page available;
break;
}
}

private void calculateHeightAndApply(int currentHeight, int nextHeight, float positionOffset) {
if (positionOffset==0) {
return;
}
int diff = nextHeight - currentHeight;
int newHeight = (int) ((positionOffset*diff));
mToolbar.setMinimumHeight(currentHeight+newHeight);
}

@Override
public void onPageSelected(int position) {}

@Override
public void onPageScrollStateChanged(int state) {}

class MyPagerAdapter extends FragmentStatePagerAdapter {

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

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return BlankFragment.newInstance("My toolbar height is :" + heightForPage0 + " px") ;
case 1:
return BlankFragment.newInstance("My toolbar height is :" + heightForPage1 + " px");
case 2:
return BlankFragment.newInstance("My toolbar height is :" + heightForPage2 + " px");
case 3:
return BlankFragment.newInstance("My toolbar height is :" + heightForPage3 + " px");
default:
return null;
}
}

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

0 comments on commit 69df84e

Please sign in to comment.