Java tutorial
/* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hataskrau.ui.issue.detailed; import android.content.Intent; import android.content.res.ColorStateList; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; import android.util.DisplayMetrics; import android.view.View; import android.widget.TextView; import com.fab.FloatingActionButton; import com.hataskrau.R; import com.hataskrau.data.dao.IssueDAO; import com.hataskrau.data.database.DbManager; import com.hataskrau.data.model.Issue; import com.hataskrau.ui.comments.CommentsFragment; import com.hataskrau.utils.image.ImageCache; import com.hataskrau.utils.image.ImageFetcher; import com.hataskrau.utils.image.Images; //import com.hataskrau.data.demo.IssueDemoStorage; public class DetailedIssueActivity extends FragmentActivity implements View.OnClickListener { private static final String IMAGE_CACHE_DIR = "images"; public static final String EXTRA_ISSUE_ID = "extra_issue_id"; private ImagePagerAdapter mAdapter; private ImageFetcher mImageFetcher; private ViewPager mPager; private TextView tvTitle; private TextView tvAddress; private View vHeader; private FloatingActionButton btSendEmail; private TextView tvDescriptionTitle; private TextView tvDescription; private TextView tvSolutionTitle; private TextView tvSolution; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_datailed_issue); tvTitle = (TextView) findViewById(R.id.activity_detailed_issue_tvTitle); tvAddress = (TextView) findViewById(R.id.activity_detailed_issue_tvAddress); vHeader = findViewById(R.id.activity_detailed_issue_vHeader); btSendEmail = (FloatingActionButton) findViewById(R.id.activity_detailed_issue_btSendEmail); tvDescriptionTitle = (TextView) findViewById(R.id.activity_detailed_issue_tvDescriptionTitle); tvDescription = (TextView) findViewById(R.id.activity_detailed_issue_tvDescription); tvSolutionTitle = (TextView) findViewById(R.id.activity_detailed_issue_tvSolutionTitle); tvSolution = (TextView) findViewById(R.id.activity_detailed_issue_tvSolution); btSendEmail.setOnClickListener(this); final DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final int height = displayMetrics.heightPixels; final int width = displayMetrics.widthPixels; final int longest = (height > width ? height : width) / 2; ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(this, IMAGE_CACHE_DIR); cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of app memory // The ImageFetcher takes care of loading images into our ImageView children asynchronously mImageFetcher = new ImageFetcher(this, longest); mImageFetcher.addImageCache(getSupportFragmentManager(), cacheParams); mImageFetcher.setImageFadeIn(false); // Set up ViewPager and backing adapter mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), Images.imageUrls); mPager = (ViewPager) findViewById(R.id.activity_detailed_issue_vpImages); mPager.setAdapter(mAdapter); mPager.setPageMargin((int) getResources().getDimension(R.dimen.horizontal_page_margin)); mPager.setOffscreenPageLimit(2); // Set the current item based on the extra passed in to this activity String issueId = getIntent().getStringExtra(EXTRA_ISSUE_ID); // Toast.makeText(this, "issueId = " + issueId, Toast.LENGTH_SHORT).show(); if (issueId != null) { IssueDAO issueDAO = DbManager.getHelper().getIssueTable(); Issue issue = issueDAO.getDetailedIssue(issueId); tvTitle.setText(issue.getTitle()); tvAddress.setText(issue.getAddress()); int primaryStatusColor; if (issue.getStatus() != null) primaryStatusColor = getResources().getColor(issue.getStatus().getPrimaryColorId()); else primaryStatusColor = getResources().getColor(R.color.material_grey_700); vHeader.setBackgroundColor(primaryStatusColor); if (issue.getSynopsys() == null) { tvDescriptionTitle.setVisibility(View.GONE); tvDescription.setVisibility(View.GONE); } else { tvDescriptionTitle.setTextColor(ColorStateList.valueOf(primaryStatusColor)); tvDescription.setText(issue.getSynopsys()); } if (issue.getSolution() == null) { tvSolutionTitle.setVisibility(View.GONE); tvSolution.setVisibility(View.GONE); } else { tvSolutionTitle.setTextColor(ColorStateList.valueOf(primaryStatusColor)); tvSolution.setText(issue.getSolution()); } getFragmentManager().beginTransaction() .add(R.id.comments_container, CommentsFragment.newInstance(issueId)).commit(); } } @Override public void onResume() { super.onResume(); mImageFetcher.setExitTasksEarly(false); } @Override protected void onPause() { super.onPause(); mImageFetcher.setExitTasksEarly(true); mImageFetcher.flushCache(); } @Override protected void onDestroy() { super.onDestroy(); mImageFetcher.closeCache(); } public ImageFetcher getImageFetcher() { return mImageFetcher; } @Override public void onClick(View v) { Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.putExtra(Intent.EXTRA_EMAIL, "RAYLYAN.E.V@MAIL.COM"); sendBroadcast(emailIntent); } }