Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2# fix bug that can not update items when count=2
- Loading branch information
shenxiaoliang
committed
Nov 26, 2018
1 parent
523d448
commit 2ae71ab
Showing
10 changed files
with
218 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,65 @@ | ||
package com.example.app; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.animation.AccelerateDecelerateInterpolator; | ||
import android.view.animation.OvershootInterpolator; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
import android.widget.EditText; | ||
|
||
import com.example.app.adapter.BannerAdapter2; | ||
import com.switcher.AutoSwitchView; | ||
import com.switcher.base.BaseSwitchView; | ||
import com.switcher.builder.CarouselStrategyBuilder; | ||
import com.switcher.builder.ContinuousStrategyBuilder; | ||
import com.switcher.builder.DirectionMode; | ||
|
||
/** | ||
* Created by shenxl on 2018/7/21. | ||
*/ | ||
|
||
public class StartActivity extends Activity { | ||
|
||
private static final int REQUEST_EXTERNAL_STORAGE = 1; | ||
private static String[] PERMISSIONS_STORAGE = { | ||
"android.permission.READ_EXTERNAL_STORAGE", | ||
"android.permission.WRITE_EXTERNAL_STORAGE" }; | ||
private AutoSwitchView mAswBanner; | ||
private EditText mContentEdt, mCountEdt; | ||
private BannerAdapter2 mBannerAdapter = new BannerAdapter2(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_start); | ||
|
||
findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() { | ||
mContentEdt = (EditText) findViewById(R.id.edt_content); | ||
mCountEdt = (EditText) findViewById(R.id.edt_count); | ||
mAswBanner = (AutoSwitchView) findViewById(R.id.start_banner); | ||
mAswBanner.setAdapter(mBannerAdapter); | ||
mAswBanner.setSwitchStrategy( | ||
new CarouselStrategyBuilder(). | ||
setAnimDuration(900). | ||
setInterpolator(new AccelerateDecelerateInterpolator()). | ||
setMode(DirectionMode.right2Left). | ||
build() | ||
); | ||
findViewById(R.id.btn_save).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
startActivity(new Intent(StartActivity.this, MainActivity.class)); | ||
int count = 0; | ||
try { | ||
count = Integer.parseInt(mCountEdt.getText().toString()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
mBannerAdapter.setCount(count); | ||
mBannerAdapter.setTitle(mContentEdt.getText().toString()); | ||
mAswBanner.startSwitcher(); | ||
} | ||
}); | ||
verifyStoragePermissions(this); | ||
} | ||
|
||
public static void verifyStoragePermissions(Activity activity) { | ||
try { | ||
int permission = ActivityCompat.checkSelfPermission(activity, | ||
"android.permission.WRITE_EXTERNAL_STORAGE"); | ||
if (permission != PackageManager.PERMISSION_GRANTED) { | ||
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE); | ||
mContentEdt.setText(mBannerAdapter.getTitle()); | ||
mCountEdt.setText(mBannerAdapter.getCount()+""); | ||
|
||
findViewById(R.id.btn_example).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
startActivity(new Intent(StartActivity.this, MainActivity.class)); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/example/app/adapter/BannerAdapter2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.app.adapter; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.example.app.R; | ||
import com.switcher.base.BaseSwitchView; | ||
|
||
/** | ||
* Created by shenxl on 2018/11/26. | ||
*/ | ||
public class BannerAdapter2 extends BaseSwitchView.AbsBaseAdapter { | ||
private int count = 3; | ||
private String title = "This is banner"; | ||
|
||
@Override | ||
public View makeView(Context context) { | ||
return LayoutInflater.from(context).inflate(R.layout.start_banner_2, null, false); | ||
} | ||
|
||
@Override | ||
public void updateItem(View view, int position) { | ||
View container = view.findViewById(R.id.banner_container); | ||
((TextView) view.findViewById(R.id.banner_title)).setText(title); | ||
((TextView) view.findViewById(R.id.banner_pos)).setText("X"+position); | ||
switch (position % 3) { | ||
case 0: | ||
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimary)); | ||
break; | ||
case 1: | ||
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimaryDark)); | ||
break; | ||
default: | ||
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorAccent)); | ||
break; | ||
} | ||
|
||
} | ||
|
||
public void setCount(int count) { | ||
this.count = count; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,92 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
<android.support.constraint.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center"> | ||
|
||
<com.switcher.AutoSwitchView | ||
android:id="@+id/start_banner" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
app:switcher_repeatCount="-1" | ||
app:switcher_autoStart="true" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
|
||
<TextView | ||
android:id="@+id/tv_content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="16sp" | ||
android:textColor="#000000" | ||
android:text="content:" | ||
android:layout_marginTop="30dp" | ||
android:layout_marginLeft="15dp" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/start_banner"/> | ||
|
||
<EditText | ||
android:id="@+id/edt_content" | ||
android:layout_width="0dp" | ||
android:layout_height="49dp" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="15dp" | ||
android:background="@null" | ||
android:hint="modify content" | ||
android:singleLine="true" | ||
android:textColorHint="#cccccc" | ||
android:textColor="#535353" | ||
android:textSize="15sp" | ||
app:layout_constraintLeft_toRightOf="@id/tv_content" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintBaseline_toBaselineOf="@id/tv_content" /> | ||
|
||
<EditText | ||
android:id="@+id/edt_count" | ||
android:layout_width="0dp" | ||
android:layout_height="49dp" | ||
android:layout_marginTop="10dp" | ||
android:inputType="number" | ||
android:background="@null" | ||
android:hint="modify count" | ||
android:singleLine="true" | ||
android:textColorHint="#cccccc" | ||
android:textSize="15sp" | ||
app:layout_constraintLeft_toLeftOf="@id/edt_content" | ||
app:layout_constraintRight_toRightOf="@id/edt_content" | ||
app:layout_constraintTop_toBottomOf="@id/edt_content" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_count" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="16sp" | ||
android:textColor="#000000" | ||
android:text="count:" | ||
app:layout_constraintLeft_toLeftOf="@id/tv_content" | ||
app:layout_constraintBaseline_toBaselineOf="@id/edt_count"/> | ||
|
||
<Button | ||
android:id="@+id/btn_save" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="20dp" | ||
android:text="Save changes" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/edt_count"/> | ||
|
||
<Button | ||
android:id="@+id/btn_start" | ||
android:id="@+id/btn_example" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:text="See more examples"/> | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginRight="20dp" | ||
android:layout_marginBottom="40dp" | ||
android:text="More examples" | ||
app:layout_constraintBottom_toBottomOf="parent"/> | ||
|
||
</LinearLayout> | ||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:id="@+id/banner_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
> | ||
|
||
<TextView | ||
android:id="@+id/banner_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginRight="20dp" | ||
android:layout_marginTop="40dp" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/banner_pos" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textColor="@android:color/black" | ||
android:textSize="22sp" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="5dp" | ||
android:layout_marginBottom="35dp" | ||
/> | ||
|
||
</LinearLayout> |
Oops, something went wrong.