Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.77 KB | None | 0 0
  1. @Override
  2. protected void onCreate (Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_main);
  5.  
  6. ImageView imageView1 = (ImageView) findViewById( R.id.imageView1 );
  7. imageView1.setOnClickListener( this );
  8.  
  9. ImageView imageView2 = (ImageView) findViewById( R.id.imageView2 );
  10. imageView2.setOnClickListener( this );
  11.  
  12. ImageView imageView3 = (ImageView) findViewById( R.id.imageView3 );
  13. imageView3.setOnClickListener( this );
  14.  
  15. ImageView imageView4 = (ImageView) findViewById( R.id.imageView4 );
  16. imageView4.setOnClickListener( this );
  17.  
  18. }
  19.  
  20. @Override
  21. public void onClick(View v) {
  22. switch (v.getId()) {
  23.  
  24. case R.id.imageView1:
  25. openActivity1();
  26. Intent intent = new Intent( this, Activity1.class );
  27. startActivity( intent );
  28.  
  29. break;
  30.  
  31. case R.id.imageView2:
  32. openActivity2();
  33. Intent intent1 = new Intent( this, Activity2.class );
  34. startActivity( intent1 );
  35.  
  36. break;
  37.  
  38. case R.id.imageView3:
  39. openActivity3();
  40. Intent intent2 = new Intent( this, Activity3.class );
  41. startActivity( intent2 );
  42.  
  43. break;
  44.  
  45. case R.id.imageView4:
  46.  
  47. openActivity4();
  48. Intent intent3 = new Intent( this, Activity4.class );
  49. startActivity( intent3 );
  50.  
  51. break;
  52.  
  53. default:
  54.  
  55. openActivity1();
  56.  
  57. }
  58.  
  59. }
  60.  
  61. private void openActivity1() {
  62. }
  63. private void openActivity2() {
  64. }
  65. private void openActivity3() {
  66. }
  67. private void openActivity4() {
  68. } }
  69.  
  70. private static final String TAG = LoginWithAmazonActivity.class.getName();
  71.  
  72. private TextView mProfileText;
  73. private Button mLogoutButton;
  74. private ProgressBar mLogInProgress;
  75. private RequestContext requestContext;
  76. private boolean mIsLoggedIn;
  77. private View mLoginButton;
  78.  
  79. @Override
  80. protected void onCreate(Bundle savedInstanceState) {
  81. super.onCreate(savedInstanceState);
  82.  
  83. requestContext = RequestContext.create(this);
  84.  
  85.  
  86.  
  87. requestContext.registerListener(new AuthorizeListener() {
  88.  
  89. @Override
  90. public void onSuccess(AuthorizeResult authorizeResult) {
  91. runOnUiThread(new Runnable() {
  92. @Override
  93. public void run() {
  94. // At this point we know the authorization completed, so remove the ability to return to the app to sign-in again
  95. setLoggingInState(true);
  96. }
  97. });
  98. fetchUserProfile();
  99. }
  100.  
  101.  
  102. @Override
  103. public void onError(AuthError authError) {
  104. Log.e(TAG, "AuthError during authorization", authError);
  105. runOnUiThread(new Runnable() {
  106. @Override
  107. public void run() {
  108. showAuthToast("Error during authorization. Please try again.");
  109. resetProfileView();
  110. setLoggingInState(false);
  111. }
  112. });
  113. }
  114.  
  115.  
  116. @Override
  117. public void onCancel(AuthCancellation authCancellation) {
  118. Log.e(TAG, "User cancelled authorization");
  119. runOnUiThread(new Runnable() {
  120. @Override
  121. public void run() {
  122. showAuthToast("Authorization cancelled");
  123. resetProfileView();
  124. }
  125. });
  126. }
  127. });
  128.  
  129.  
  130. setContentView(R.layout.activity_main);
  131. initializeUI();
  132.  
  133. }
  134.  
  135.  
  136. @Override
  137. protected void onResume() {
  138. super.onResume();
  139. requestContext.onResume();
  140. }
  141.  
  142. @Override
  143. protected void onStart() {
  144. super.onStart();
  145. Scope[] scopes = {ProfileScope.profile(), ProfileScope.postalCode()};
  146. AuthorizationManager.getToken(this, scopes, new Listener<AuthorizeResult, AuthError>() {
  147. @Override
  148. public void onSuccess(AuthorizeResult result) {
  149. if (result.getAccessToken() != null) {
  150. /* The user is signed in */
  151. fetchUserProfile();
  152. } else {
  153.  
  154. }
  155. }
  156.  
  157. @Override
  158. public void onError(AuthError ae) {
  159. /* The user is not signed in */
  160. }
  161. });
  162. }
  163.  
  164.  
  165. private void fetchUserProfile() {
  166. User.fetch(this, new Listener<User, AuthError>() {
  167.  
  168.  
  169. @Override
  170. public void onSuccess(User user) {
  171. final String name = user.getUserName();
  172. final String email = user.getUserEmail();
  173. final String account = user.getUserId();
  174. final String zipCode = user.getUserPostalCode();
  175.  
  176. runOnUiThread(new Runnable() {
  177. @Override
  178. public void run() {
  179. updateProfileData(name, email, account, zipCode);
  180. }
  181. });
  182. }
  183.  
  184.  
  185. @Override
  186. public void onError(AuthError ae) {
  187. runOnUiThread(new Runnable() {
  188. @Override
  189. public void run() {
  190. setLoggedOutState();
  191. String errorMessage = "Error retrieving profile information.nPlease log in again";
  192. Toast errorToast = Toast.makeText(getApplicationContext(), errorMessage,
  193.  
  194. private void updateProfileData(String name, String email, String account, String zipCode) {
  195. StringBuilder profileBuilder = new StringBuilder();
  196. profileBuilder.append(String.format("Welcome, %s!n", name));
  197. profileBuilder.append(String.format("Your email is %sn", email));
  198. profileBuilder.append(String.format("Your zipCode is %sn", zipCode));
  199. final String profile = profileBuilder.toString();
  200. Log.d(TAG, "Profile Response: " + profile);
  201. runOnUiThread(new Runnable() {
  202. @Override
  203. public void run() {
  204. updateProfileView(profile);
  205. setLoggedInState();
  206. }
  207. });
  208. }
  209.  
  210.  
  211. private void initializeUI() {
  212.  
  213. mLoginButton = findViewById(R.id.login_with_amazon);
  214. mLoginButton.setOnClickListener(new View.OnClickListener() {
  215. @Override
  216. public void onClick(View view) {
  217. AuthorizationManager.authorize(
  218. new AuthorizeRequest.Builder(requestContext)
  219. .addScopes(ProfileScope.profile(), ProfileScope.postalCode())
  220. .build()
  221. );
  222. }
  223. });
  224.  
  225. // Find the button with the logout ID and set up a click handler
  226. View logoutButton = findViewById(R.id.logout);
  227. logoutButton.setOnClickListener(new View.OnClickListener() {
  228.  
  229. @Override
  230. public void onClick(View v) {
  231. AuthorizationManager.signOut(getApplicationContext(), new
  232.  
  233. @Override
  234. public void onError(AuthError authError) {
  235. Log.e(TAG, "Error clearing authorization state.", authError);
  236. }
  237. });
  238. }
  239. });
  240.  
  241. String logoutText = getString(R.string.logout);
  242. mProfileText = (TextView) findViewById(R.id.profile_info);
  243. mLogoutButton = (Button) logoutButton;
  244. mLogoutButton.setText(logoutText);
  245. mLogInProgress = (ProgressBar) findViewById(R.id.log_in_progress);
  246. }
  247.  
  248.  
  249. private void updateProfileView(String profileInfo) {
  250. Log.d(TAG, "Updating profile view");
  251. mProfileText.setText(profileInfo);
  252. }
  253.  
  254.  
  255. private void resetProfileView() {
  256. setLoggingInState(false);
  257. mProfileText.setText(getString(R.string.default_message));
  258. }
  259.  
  260.  
  261. private void setLoggedInState() {
  262. mLoginButton.setVisibility(Button.GONE);
  263. setLoggedInButtonsVisibility(Button.VISIBLE);
  264. mIsLoggedIn = true;
  265. setLoggingInState(false);
  266. }
  267.  
  268.  
  269. private void setLoggedOutState() {
  270. mLoginButton.setVisibility(Button.VISIBLE);
  271. setLoggedInButtonsVisibility(Button.GONE);
  272. mIsLoggedIn = false;
  273. resetProfileView();
  274. }
  275.  
  276.  
  277. private void setLoggedInButtonsVisibility(int visibility) {
  278. mLogoutButton.setVisibility(visibility);
  279. }
  280.  
  281. private void setLoggingInState(final boolean loggingIn) {
  282. if (loggingIn) {
  283. mLoginButton.setVisibility(Button.GONE);
  284. setLoggedInButtonsVisibility(Button.GONE);
  285. mLogInProgress.setVisibility(ProgressBar.VISIBLE);
  286. mProfileText.setVisibility(TextView.GONE);
  287. } else {
  288. if (mIsLoggedIn) {
  289. setLoggedInButtonsVisibility(Button.VISIBLE);
  290. } else {
  291. mLoginButton.setVisibility(Button.VISIBLE);
  292. }
  293. mLogInProgress.setVisibility(ProgressBar.GONE);
  294. mProfileText.setVisibility(TextView.VISIBLE);
  295. }
  296. }
  297.  
  298. private void showAuthToast(String authToastMessage) {
  299. Toast authToast = Toast.makeText(getApplicationContext(), authToastMessage, Toast.LENGTH_LONG);
  300. authToast.setGravity(Gravity.CENTER, 0, 0);
  301. authToast.show();
  302. }
  303. }
  304.  
  305. <ImageView
  306. android:id="@+id/imageView1"
  307. android:layout_width="150dp"
  308. android:layout_height="150dp"
  309. android:src="@drawable/aggressive_momemnts"
  310. android:clickable="true"
  311. android:focusable="true"
  312.  
  313. android:contentDescription="@string/todo" />
  314.  
  315. <ImageView
  316. android:id="@+id/imageView2"
  317. android:layout_width="150dp"
  318. android:layout_height="150dp"
  319. android:layout_marginStart="30dp"
  320. android:clickable="true"
  321. android:focusable="true"
  322. android:visibility="gone"
  323. android:src="@drawable/best_moments"
  324. android:layout_marginLeft="30dp"
  325. android:contentDescription="@string/todo" />
  326.  
  327. <ImageView
  328. android:id="@+id/imageView3"
  329. android:layout_width="150dp"
  330. android:layout_height="150dp"
  331. android:layout_marginStart="30dp"
  332. android:layout_marginEnd="99dp"
  333. android:clickable="true"
  334. android:focusable="true"
  335. android:src="@drawable/best_player"
  336. android:layout_marginLeft="30dp"
  337. android:layout_marginRight="99dp"
  338. android:contentDescription="@string/todo" />
  339.  
  340. <ImageView
  341. android:id="@+id/imageView4"
  342. android:layout_width="150dp"
  343. android:layout_height="150dp"
  344. android:layout_marginStart="30dp"
  345. android:clickable="true"
  346. android:focusable="true"
  347. android:src="@drawable/coach"
  348. android:layout_marginLeft="30dp"
  349. android:contentDescription="@string/todo" />
  350.  
  351.  
  352. <FrameLayout
  353. android:layout_width="match_parent"
  354. android:layout_height="match_parent"
  355. android:id="@+id/fragment"/>
  356.  
  357. <ProgressBar
  358. android:id="@+id/log_in_progress"
  359. android:layout_width="wrap_content"
  360. android:layout_height="wrap_content"
  361.  
  362. style="@android:style/Widget.ProgressBar.Inverse"/>
  363.  
  364.  
  365.  
  366.  
  367.  
  368. </LinearLayout>
  369. <TextView
  370. android:id="@+id/profile_info"
  371. android:layout_width="310dp"
  372. android:layout_height="wrap_content"
  373. android:text="@string/default_message"
  374. android:textSize="15sp"
  375. android:gravity="center"
  376. android:layout_gravity="center"/>
  377.  
  378. <ImageButton
  379. android:layout_width="wrap_content"
  380. android:layout_height="wrap_content"
  381. android:layout_alignParentBottom="true"
  382. android:layout_centerHorizontal="true"
  383. android:layout_marginBottom="10dp"
  384. android:id="@+id/login_with_amazon"
  385. android:src="@color/login_button_image_state"
  386. android:background="@android:color/transparent"
  387. android:padding="0dp"
  388. android:contentDescription="@string/login_button_content_description"
  389.  
  390. <Button
  391. android:layout_width="wrap_content"
  392. android:layout_height="wrap_content"
  393. android:layout_alignParentTop="true"
  394. android:layout_alignParentRight="true"
  395. android:layout_marginTop="10dp"
  396. android:layout_marginRight="10dp"
  397. android:id="@+id/logout"
  398. android:text="@string/logout"
  399. android:visibility="gone"
  400. android:clickable="true"
  401. android:textColor="@color/logout_text_color_state"
  402. android:paddingBottom="10dp"
  403. android:layout_alignParentEnd="true"
  404. android:layout_marginEnd="10dp" />
  405.  
  406. <Button
  407. android:layout_width="wrap_content"
  408. android:layout_height="wrap_content"
  409. android:layout_alignParentTop="true"
  410. android:layout_alignParentRight="true"
  411. android:layout_marginTop="10dp"
  412. android:layout_marginRight="10dp"
  413. android:id="@+id/return_to_app"
  414. android:text="@string/return_to_app"
  415. android:visibility="gone"
  416. android:clickable="true"
  417. android:textColor="@color/logout_text_color_state"
  418. android:paddingBottom="10dp"
  419. android:layout_alignParentEnd="true"
  420. android:layout_marginEnd="10dp" /> </RelativeLayout>
  421.  
  422. <?xml version="1.0" encoding="utf-8"?>
  423. <RelativeLayout
  424. xmlns:android="http://schemas.android.com/apk/res/android"
  425. xmlns:app="http://schemas.android.com/apk/res-auto"
  426. xmlns:tools="http://schemas.android.com/tools"
  427. android:layout_width="match_parent"
  428. android:layout_height="match_parent"
  429. tools:context=".Activity1">
  430.  
  431. <VideoView
  432. android:layout_width="match_parent"
  433. android:layout_height="match_parent"
  434. android:id="@+id/v1"
  435. />
  436. </RelativeLayout>
  437.  
  438. @Override
  439. protected void onCreate(Bundle savedInstanceState) {
  440. super.onCreate(savedInstanceState);
  441. setContentView(R.layout.activity_1);
  442.  
  443. VideoView v1 = (VideoView) findViewById( R.id.v1 );
  444.  
  445. v1.setVideoURI( Uri.parse( "https//.mp4" ) );
  446. v1.start();
  447. v1.requestFocus();
  448. v1.setKeepScreenOn( true );
  449. } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement