Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.68 KB | None | 0 0
  1. import android.support.v7.app.AppCompatActivity;
  2. import android.os.Bundle;
  3.  
  4. import android.app.ActionBar;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.graphics.Color;
  8. import android.os.Bundle;
  9. import android.preference.PreferenceManager;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.view.Menu;
  12. import android.view.MenuInflater;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.View.OnClickListener;
  16. import android.widget.Button;
  17. import android.widget.Toast;
  18.  
  19. import de.mrapp.android.sidebar.ContentMode;
  20. import de.mrapp.android.sidebar.DragMode;
  21. import de.mrapp.android.sidebar.Location;
  22. import de.mrapp.android.sidebar.Sidebar;
  23. import de.mrapp.android.sidebar.SidebarListener;
  24.  
  25. /**
  26. * The example app's main activity.
  27. *
  28. * @author Michael Rapp
  29. */
  30. public class TryActivity extends AppCompatActivity implements SidebarListener {
  31.  
  32. /**
  33. * The sidebar.
  34. */
  35. private Sidebar sidebar;
  36. Button btnSaver;
  37.  
  38. /**
  39. * Initializes the sidebar.
  40. */
  41. private void initializeSidebar() {
  42. sidebar = (Sidebar) findViewById(R.id.sidebar);
  43. sidebar.addSidebarListener(this);
  44. }
  45.  
  46. /**
  47. * Initializes the location of the sidebar by retrieving the appropriate setting from the shared
  48. * preferences.
  49. *
  50. * @param sharedPreferences
  51. * The shared preferences, the settings should be retrieved from, as an instance of the
  52. * type {@link SharedPreferences}
  53. */
  54. private void initializeSidebarLocation(final SharedPreferences sharedPreferences) {
  55. String key = getString(R.string.location_preference_key);
  56. String defaultValue = getString(R.string.location_preference_default_value);
  57. int location = Integer.valueOf(sharedPreferences.getString(key, defaultValue));
  58. sidebar.setLocation(Location.fromValue(location));
  59. }
  60.  
  61. /**
  62. * Initializes the width of the sidebar by retrieving the appropriate setting from the shared
  63. * preferences.
  64. *
  65. * @param sharedPreferences
  66. * The shared preferences, the settings should be retrieved from, as an instance of the
  67. * type {@link SharedPreferences}
  68. */
  69. private void initializeSidebarWidth(final SharedPreferences sharedPreferences) {
  70. String key = getString(R.string.sidebar_width_preference_key);
  71. String defaultValue = getString(R.string.sidebar_width_default_value);
  72. float sidebarWidth = Float.valueOf(sharedPreferences.getString(key, defaultValue));
  73. sidebar.setSidebarWidth(sidebarWidth);
  74. }
  75.  
  76. /**
  77. * Initializes the maximum width of the sidebar by retrieving the appropriate setting from the
  78. * shared preferences.
  79. *
  80. * @param sharedPreferences
  81. * The shared preferences, the settings should be retrieved from, as an instance of the
  82. * type {@link SharedPreferences}
  83. */
  84. private void initializeMaxSidebarWidth(final SharedPreferences sharedPreferences) {
  85. String key = getString(R.string.max_sidebar_width_preference_key);
  86. String defaultValue = getString(R.string.max_sidebar_width_preference_default_value);
  87. int maxSidebarWidth = Integer.valueOf(sharedPreferences.getString(key, defaultValue));
  88. sidebar.setMaxSidebarWidth(maxSidebarWidth);
  89. }
  90.  
  91. /**
  92. * Initializes the offset of the sidebar by retrieving the appropriate setting from the shared
  93. * preferences.
  94. *
  95. * @param sharedPreferences
  96. * The shared preferences, the settings should be retrieved from, as an instance of the
  97. * type {@link SharedPreferences}
  98. */
  99. private void initializeSidebarOffset(final SharedPreferences sharedPreferences) {
  100. String key = getString(R.string.sidebar_offset_preference_key);
  101. String defaultValue = getString(R.string.sidebar_offset_preference_default_value);
  102. float sidebarOffset = Float.valueOf(sharedPreferences.getString(key, defaultValue));
  103. sidebar.setSidebarOffset(sidebarOffset);
  104. }
  105.  
  106. /**
  107. * Initializes the maximum offset of the sidebar by retrieving the appropriate setting from the
  108. * shared preferences.
  109. *
  110. * @param sharedPreferences
  111. * The shared preferences, the settings should be retrieved from, as an instance of the
  112. * type {@link SharedPreferences}
  113. */
  114. private void initializeMaxSidebarOffset(final SharedPreferences sharedPreferences) {
  115. String key = getString(R.string.max_sidebar_offset_preference_key);
  116. String defaultValue = getString(R.string.max_sidebar_offset_preference_default_value);
  117. int maxSidebarOffset = Integer.valueOf(sharedPreferences.getString(key, defaultValue));
  118. sidebar.setMaxSidebarOffset(maxSidebarOffset);
  119. }
  120.  
  121. /**
  122. * Initializes, whether the sidebar should be shown by default, by retrieving the appropriate
  123. * setting from the shared preferences.
  124. *
  125. * @param sharedPreferences
  126. * The shared preferences, the settings should be retrieved from, as an instance of the
  127. * type {@link SharedPreferences}
  128. */
  129. private void initializeShowByDefault(final SharedPreferences sharedPreferences) {
  130. String key = getString(R.string.show_preference_key);
  131. String defaultValue = getString(R.string.show_preference_default_value);
  132. boolean show = sharedPreferences.getBoolean(key, Boolean.valueOf(defaultValue));
  133.  
  134. if (show) {
  135. sidebar.showSidebar();
  136. }
  137. }
  138.  
  139. /**
  140. * Initializes the content mode by retrieving the appropriate setting from the shared
  141. * preferences.
  142. *
  143. * @param sharedPreferences
  144. * The shared preferences, the settings should be retrieved from, as an instance of the
  145. * type {@link SharedPreferences}
  146. */
  147. private void initializeContentMode(final SharedPreferences sharedPreferences) {
  148. String key = getString(R.string.content_mode_preference_key);
  149. String defaultValue = getString(R.string.content_mode_preference_default_value);
  150. int contentMode = Integer.valueOf(sharedPreferences.getString(key, defaultValue));
  151. sidebar.setContentMode(ContentMode.fromValue(contentMode));
  152. }
  153.  
  154. /**
  155. * Initializes the scroll ratio by retrieving the appropriate setting from the shared
  156. * preferences.
  157. *
  158. * @param sharedPreferences
  159. * The shared preferences, the settings should be retrieved from, as an instance of the
  160. * type {@link SharedPreferences}
  161. */
  162. private void initializeScrollRatio(final SharedPreferences sharedPreferences) {
  163. String key = getString(R.string.scroll_ratio_preference_key);
  164. String defaultValue = getString(R.string.scroll_ratio_preference_default_value);
  165. float scrollRatio = Float.valueOf(sharedPreferences.getString(key, defaultValue));
  166. sidebar.setScrollRatio(scrollRatio);
  167. }
  168.  
  169. /**
  170. * Initializes, whether the sidebar should be hidden when the back button is clicked, by
  171. * retrieving the appropriate setting from the shared preferences.
  172. *
  173. * @param sharedPreferences
  174. * The shared preferences, the settings should be retrieved from, as an instance of the
  175. * type {@link SharedPreferences}
  176. */
  177. private void initializeHideOnBackButton(final SharedPreferences sharedPreferences) {
  178. String key = getString(R.string.hide_on_back_button_preference_key);
  179. String defaultValue = getString(R.string.hide_on_back_button_default_value);
  180. boolean hideOnBackButton = sharedPreferences.getBoolean(key, Boolean.valueOf(defaultValue));
  181. sidebar.hideOnBackButton(hideOnBackButton);
  182. }
  183.  
  184. /**
  185. * Initializes, whether the sidebar should be hidden when the content is clicked, by retrieving
  186. * the appropriate setting from the shared preferences.
  187. *
  188. * @param sharedPreferences
  189. * The shared preferences, the settings should be retrieved from, as an instance of the
  190. * type {@link SharedPreferences}
  191. */
  192. private void initializeHideOnContentClick(final SharedPreferences sharedPreferences) {
  193. String key = getString(R.string.hide_on_content_click_preference_key);
  194. String defaultValue = getString(R.string.hide_on_content_click_preference_default_value);
  195. boolean hideOnContentClick =
  196. sharedPreferences.getBoolean(key, Boolean.valueOf(defaultValue));
  197. sidebar.hideOnContentClick(hideOnContentClick);
  198. }
  199.  
  200. /**
  201. * Initializes, whether the sidebar should be shown when it is clicked, by retrieving the
  202. * appropriate setting from the shared preferences.
  203. *
  204. * @param sharedPreferences
  205. * The shared preferences, the settings should be retrieved from, as an instance of the
  206. * type {@link SharedPreferences}
  207. */
  208. private void initializeShowOnSidebarClick(final SharedPreferences sharedPreferences) {
  209. String key = getString(R.string.show_on_sidebar_click_preference_key);
  210. String defaultValue = getString(R.string.show_on_sidebar_click_preference_default_value);
  211. boolean showOnSidebarClick =
  212. sharedPreferences.getBoolean(key, Boolean.valueOf(defaultValue));
  213. sidebar.showOnSidebarClick(showOnSidebarClick);
  214. }
  215.  
  216. /**
  217. * Initializes the animation speed by retrieving the appropriate setting from the shared
  218. * preferences.
  219. *
  220. * @param sharedPreferences
  221. * The shared preferences, the settings should be retrieved from, as an instance of the
  222. * type {@link SharedPreferences}
  223. */
  224. private void initializeAnimationSpeed(final SharedPreferences sharedPreferences) {
  225. String key = getString(R.string.animation_speed_preference_key);
  226. String defaultValue = getString(R.string.animation_speed_preference_default_value);
  227. float animationSpeed = Float.valueOf(sharedPreferences.getString(key, defaultValue));
  228. sidebar.setAnimationSpeed(animationSpeed);
  229. }
  230.  
  231. /**
  232. * Initializes the drag threshold by retrieving the appropriate setting from the shared
  233. * preferences.
  234. *
  235. * @param sharedPreferences
  236. * The shared preferences, the settings should be retrieved from, as an instance of the
  237. * type {@link SharedPreferences}
  238. */
  239. private void initializeDragThreshold(final SharedPreferences sharedPreferences) {
  240. String key = getString(R.string.drag_threshold_preference_key);
  241. String defaultValue = getString(R.string.drag_threshold_preference_default_value);
  242. float dragThreshold = Float.valueOf(sharedPreferences.getString(key, defaultValue));
  243. sidebar.setDragThreshold(dragThreshold);
  244. }
  245.  
  246. /**
  247. * Initializes the drag mode, which is used when the sidebar is hidden, by retrieving the
  248. * appropriate setting from the shared preferences.
  249. *
  250. * @param sharedPreferences
  251. * The shared preferences, the settings should be retrieved from, as an instance of the
  252. * type {@link SharedPreferences}
  253. */
  254. private void initializeDragModeWhenHidden(final SharedPreferences sharedPreferences) {
  255. String key = getString(R.string.drag_mode_when_hidden_preference_key);
  256. String defaultValue = getString(R.string.drag_mode_when_hidden_preference_default_value);
  257. int dragMode = Integer.valueOf(sharedPreferences.getString(key, defaultValue));
  258. sidebar.setDragModeWhenHidden(DragMode.fromValue(dragMode));
  259. }
  260.  
  261. /**
  262. * Initializes the drag mode, which is used when the sidebar is shown, by retrieving the
  263. * appropriate setting from the shared preferences.
  264. *
  265. * @param sharedPreferences
  266. * The shared preferences, the settings should be retrieved from, as an instance of the
  267. * type {@link SharedPreferences}
  268. */
  269. private void initializeDragModeWhenShown(final SharedPreferences sharedPreferences) {
  270. String key = getString(R.string.drag_mode_when_shown_preference_key);
  271. String defaultValue = getString(R.string.drag_mode_when_shown_preference_default_value);
  272. int dragMode = Integer.valueOf(sharedPreferences.getString(key, defaultValue));
  273. sidebar.setDragModeWhenShown(DragMode.fromValue(dragMode));
  274. }
  275.  
  276. /**
  277. * Initializes the sidebar elevation by retrieving the appropriate setting from the shared
  278. * preferences.
  279. *
  280. * @param sharedPreferences
  281. * The shared preferences, the settings should be retrieved from, as an instance of the
  282. * type {@link SharedPreferences}
  283. */
  284. private void initializeSidebarElevation(final SharedPreferences sharedPreferences) {
  285. String key = getString(R.string.sidebar_elevation_preference_key);
  286. String defaultValue = getString(R.string.sidebar_elevation_preference_default_value);
  287. String sidebarElevation = sharedPreferences.getString(key, defaultValue);
  288. sidebar.setSidebarElevation(Integer.valueOf(sidebarElevation));
  289. }
  290.  
  291. /**
  292. * Initializes the content overlay color by retrieving the appropriate setting from the shared
  293. * preferences.
  294. *
  295. * @param sharedPreferences
  296. * The shared preferences, the settings should be retrieved from, as an instance of the
  297. * type {@link SharedPreferences}
  298. */
  299. private void initializeContentOverlayColor(final SharedPreferences sharedPreferences) {
  300. String key = getString(R.string.content_overlay_color_preference_key);
  301. String defaultValue = getString(R.string.content_overlay_color_preference_default_value);
  302. String contentOverlayColor = sharedPreferences.getString(key, defaultValue);
  303. sidebar.setContentOverlayColor(Color.parseColor(contentOverlayColor));
  304. }
  305.  
  306. /**
  307. * Initializes the content overlay transparency by retrieving the appropriate setting from the
  308. * shared preferences.
  309. *
  310. * @param sharedPreferences
  311. * The shared preferences, the settings should be retrieved from, as an instance of the
  312. * type {@link SharedPreferences}
  313. */
  314. private void initializeContentOverlayTransparency(final SharedPreferences sharedPreferences) {
  315. String key = getString(R.string.content_overlay_transparency_key);
  316. String defaultValue = getString(R.string.content_overlay_transparency_default_value);
  317. float contentOverlayTransparency =
  318. Float.valueOf(sharedPreferences.getString(key, defaultValue));
  319. sidebar.setContentOverlayTransparency(contentOverlayTransparency);
  320. }
  321.  
  322. /**
  323. * Initializes the button, which allows to show the sidebar.
  324. */
  325. private void initializeShowSidebarButton() {
  326. Button showSidebarButton = (Button) findViewById(R.id.show_sidebar_button);
  327. showSidebarButton.setOnClickListener(new OnClickListener() {
  328.  
  329. @Override
  330. public void onClick(final View v) {
  331. sidebar.showSidebar();
  332. }
  333.  
  334. });
  335. }
  336.  
  337. /**
  338. * Initializes the button, which allows to hide the sidebar.
  339. */
  340. private void initializeHideSidebarButton() {
  341. Button hideSidebarButton = (Button) findViewById(R.id.hide_sidebar_button);
  342. hideSidebarButton.setOnClickListener(new OnClickListener() {
  343.  
  344. @Override
  345. public void onClick(final View v) {
  346. sidebar.hideSidebar();
  347. }
  348.  
  349. });
  350. }
  351.  
  352. @Override
  353. protected final void onCreate(final Bundle savedInstanceState) {
  354. super.onCreate(savedInstanceState);
  355. setContentView(R.layout.activity_try);
  356. initializeSidebar();
  357. initializeShowSidebarButton();
  358.  
  359. initializeHideSidebarButton();
  360.  
  361. if (savedInstanceState == null) {
  362. SharedPreferences sharedPreferences =
  363. PreferenceManager.getDefaultSharedPreferences(this);
  364. initializeSidebarLocation(sharedPreferences);
  365. initializeSidebarWidth(sharedPreferences);
  366. initializeMaxSidebarWidth(sharedPreferences);
  367. initializeSidebarOffset(sharedPreferences);
  368. initializeMaxSidebarOffset(sharedPreferences);
  369. initializeShowByDefault(sharedPreferences);
  370. initializeContentMode(sharedPreferences);
  371. initializeScrollRatio(sharedPreferences);
  372. initializeHideOnBackButton(sharedPreferences);
  373. initializeHideOnContentClick(sharedPreferences);
  374. initializeShowOnSidebarClick(sharedPreferences);
  375. initializeAnimationSpeed(sharedPreferences);
  376. initializeDragThreshold(sharedPreferences);
  377. initializeDragModeWhenHidden(sharedPreferences);
  378. initializeDragModeWhenShown(sharedPreferences);
  379. initializeSidebarElevation(sharedPreferences);
  380. initializeContentOverlayColor(sharedPreferences);
  381. initializeContentOverlayTransparency(sharedPreferences);
  382. }
  383. btnSaver=(Button)findViewById(R.id.btSaveNicke);
  384.  
  385. btnSaver.setOnClickListener(new View.OnClickListener() {
  386. @Override
  387. public void onClick(View v) {
  388.  
  389. Toast.makeText(TryActivity.this, "Status length must be less then 50 letters and more then 2 letters", Toast.LENGTH_SHORT).show();
  390.  
  391. }
  392. });//end of onclick
  393. }
  394.  
  395. @Override
  396. public final void onResume() {
  397. super.onResume();
  398.  
  399. if (sidebar.isSidebarShown()) {
  400. ActionBar actionBar = getActionBar();
  401.  
  402. if (actionBar != null) {
  403. actionBar.setDisplayHomeAsUpEnabled(true);
  404. }
  405.  
  406. setTitle(R.string.sidebar_title);
  407. }
  408. }
  409.  
  410. @Override
  411. public final boolean onCreateOptionsMenu(final Menu menu) {
  412. super.onCreateOptionsMenu(menu);
  413. MenuInflater inflater = getMenuInflater();
  414. inflater.inflate(R.menu.setting_menu, menu);
  415. return true;
  416. }
  417.  
  418.  
  419. @Override
  420. public final void onSidebarShown(final Sidebar sidebar) {
  421. ActionBar actionBar = getActionBar();
  422.  
  423. if (actionBar != null) {
  424. actionBar.setDisplayHomeAsUpEnabled(true);
  425. }
  426.  
  427. setTitle(R.string.sidebar_title);
  428. }
  429.  
  430. @Override
  431. public final void onSidebarHidden(final Sidebar sidebar) {
  432. ActionBar actionBar = getActionBar();
  433.  
  434. if (actionBar != null) {
  435. actionBar.setDisplayHomeAsUpEnabled(false);
  436. }
  437.  
  438. setTitle(R.string.app_name);
  439. }
  440.  
  441. @Override
  442. public final boolean onOptionsItemSelected(final MenuItem item) {
  443. switch (item.getItemId()) {
  444. case R.id.bkmain_menu:
  445. Intent i = new Intent(TryActivity.this, StartActivity.class);
  446. startActivity(i);
  447. finish();
  448. return true;
  449. default:
  450. break;
  451. }
  452.  
  453. return super.onOptionsItemSelected(item);
  454. }
  455.  
  456. }
  457.  
  458. <string-array name="list">
  459. <item>Happy fragment</item>
  460. <item>Fun fragment</item>
  461. <item>Change Profile Picture fragment</item>
  462. </string-array>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement