forked from xiaofeng-han/AndroidLibs
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix left & center align Remove uneccesary code
- Loading branch information
1 parent
2c187d8
commit 5110340
Showing
28 changed files
with
243 additions
and
484 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 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
94 changes: 0 additions & 94 deletions
94
app/src/main/java/com/xiaofeng/androidlibs/GeneralPreferenceFragment.java
This file was deleted.
Oops, something went wrong.
169 changes: 67 additions & 102 deletions
169
app/src/main/java/com/xiaofeng/androidlibs/MainActivity.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 |
---|---|---|
@@ -1,118 +1,83 @@ | ||
package com.xiaofeng.androidlibs; | ||
|
||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.graphics.Rect; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
import android.support.annotation.NonNull; | ||
import android.support.design.widget.BottomNavigationView; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import com.xiaofeng.flowlayoutmanager.Alignment; | ||
import com.xiaofeng.flowlayoutmanager.FlowLayoutManager; | ||
|
||
import us.feras.mdv.MarkdownView; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final int REQ_CODE_SETTINGS = 101; | ||
RecyclerView recyclerView; | ||
FlowLayoutManager flowLayoutManager; | ||
MarkdownView markdownView; | ||
private boolean settingChanged = false; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main_app_bar); | ||
Toolbar toolbar = findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
init(); | ||
} | ||
|
||
private void init() { | ||
recyclerView = findViewById(R.id.list); | ||
flowLayoutManager = new FlowLayoutManager().singleItemPerLine(); | ||
flowLayoutManager.setAutoMeasureEnabled(true); | ||
recyclerView.setLayoutManager(flowLayoutManager); | ||
recyclerView.setAdapter(new DemoAdapter(1, DemoUtil.listWords())); | ||
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() { | ||
@Override | ||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { | ||
super.getItemOffsets(outRect, view, parent, state); | ||
outRect.set(5, 5, 5, 5); | ||
} | ||
}); | ||
|
||
// markdownView = (MarkdownView)findViewById(R.id.instruction_mdown); | ||
// markdownView.loadMarkdownFile("file:///android_asset/instruction.md"); | ||
loadSettingsFromSharedPref(); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.main, menu); | ||
return super.onCreateOptionsMenu(menu); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (item.getItemId() == R.id.action_settings) { | ||
startActivityForResult(new Intent(this, SettingsActivity.class), REQ_CODE_SETTINGS); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
private void loadSettingsFromSharedPref() { | ||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); | ||
String itemsPerLineString = sharedPreferences.getString(getResources().getString(R.string.pref_key_max_items_per_line), getString(R.string.pref_max_items_per_line_default)); | ||
int itemsPerLine = Integer.valueOf(itemsPerLineString); | ||
|
||
String alignmentString = sharedPreferences.getString(getResources().getString(R.string.pref_key_alignment), getString(R.string.pref_alignment_default)); | ||
|
||
if (alignmentString.equals("0")) { | ||
flowLayoutManager.setAlignment(Alignment.LEFT); | ||
} else if (alignmentString.equals("2")) { | ||
flowLayoutManager.setAlignment(Alignment.RIGHT); | ||
} else { | ||
flowLayoutManager.setAlignment(Alignment.CENTER); | ||
RecyclerView recyclerView; | ||
FlowLayoutManager flowLayoutManager; | ||
RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() { | ||
@Override | ||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { | ||
super.getItemOffsets(outRect, view, parent, state); | ||
outRect.set(5, 5, 5, 5); | ||
} | ||
}; | ||
|
||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener | ||
= new BottomNavigationView.OnNavigationItemSelectedListener() { | ||
|
||
@Override | ||
public boolean onNavigationItemSelected(@NonNull MenuItem item) { | ||
switch (item.getItemId()) { | ||
case R.id.navigation_left: | ||
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.LEFT); | ||
|
||
recyclerView.setLayoutManager(flowLayoutManager); | ||
recyclerView.getAdapter().notifyDataSetChanged(); | ||
recyclerView.addItemDecoration(itemDecoration); | ||
|
||
return true; | ||
case R.id.navigation_center: | ||
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.CENTER); | ||
flowLayoutManager.setAutoMeasureEnabled(true); | ||
|
||
recyclerView.setLayoutManager(flowLayoutManager); | ||
recyclerView.getAdapter().notifyDataSetChanged(); | ||
recyclerView.addItemDecoration(itemDecoration); | ||
|
||
return true; | ||
case R.id.navigation_rigth: | ||
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.RIGHT); | ||
flowLayoutManager.setAutoMeasureEnabled(true); | ||
|
||
recyclerView.setLayoutManager(flowLayoutManager); | ||
recyclerView.getAdapter().notifyDataSetChanged(); | ||
recyclerView.addItemDecoration(itemDecoration); | ||
|
||
return true; | ||
} | ||
return false; | ||
} | ||
// boolean showMeta = sharedPreferences.getBoolean(getString(R.string.pref_key_show_meta), false); | ||
|
||
flowLayoutManager.maxItemsPerLine(itemsPerLine); | ||
DemoAdapter demoAdapter = (DemoAdapter)recyclerView.getAdapter(); | ||
// demoAdapter.setShowMeta(showMeta); | ||
String maxLinesPerItemString = sharedPreferences.getString(getString(R.string.pref_key_max_lines_per_item), getString(R.string.pref_max_lines_per_item_default)); | ||
int maxLinesPerItem = Integer.valueOf(maxLinesPerItemString); | ||
demoAdapter.newItems(maxLinesPerItem, DemoUtil.listWords()); | ||
recyclerView.getAdapter().notifyItemRangeChanged(0, recyclerView.getAdapter().getItemCount()); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (requestCode == REQ_CODE_SETTINGS) { | ||
settingChanged = true; | ||
} | ||
} | ||
|
||
@Override | ||
public void onWindowFocusChanged(boolean hasFocus) { | ||
super.onWindowFocusChanged(hasFocus); | ||
if (hasFocus) { | ||
if (settingChanged) { | ||
settingChanged = false; | ||
recyclerView.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
loadSettingsFromSharedPref(); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main_activity); | ||
|
||
BottomNavigationView navigation = findViewById(R.id.navigation); | ||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); | ||
|
||
recyclerView = findViewById(R.id.list); | ||
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.LEFT); | ||
flowLayoutManager.setAutoMeasureEnabled(true); | ||
recyclerView.setLayoutManager(flowLayoutManager); | ||
recyclerView.setAdapter(new DemoAdapter(DemoUtil.listWords())); | ||
recyclerView.getAdapter().notifyDataSetChanged(); | ||
recyclerView.addItemDecoration(itemDecoration); | ||
|
||
|
||
} | ||
|
||
} |
Oops, something went wrong.