Back to project page LearnByHeart.
The source code is released under:
Apache License
If you think the Android project LearnByHeart listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mps.learn.pb.ui.factivities; //w w w .ja va2 s. c o m import android.app.ProgressDialog; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.mps.learn.pb.PhraseManager; import com.mps.learn.pb.R; import com.mps.learn.pb.alarm.ReminderUtil; import com.mps.learn.pb.http.DataUpdaterCallback; import com.mps.learn.pb.http.DataUpdaterTask; import com.mps.learn.pb.model.PhraseBook; import com.mps.learn.pb.model.PhraseModel; import com.mps.learn.pb.ui.views.FoldableListLayout; import com.mps.learn.pb.ui.views.UnfoldableView; import com.mps.learn.pb.ui.views.shading.GlanceFoldShading; import com.mps.learn.pb.util.Debugger; import com.squareup.picasso.Picasso; public class UnfoldableDetailsActivity extends BaseActivity implements DataUpdaterCallback { private ListView mListView; private View mListTouchInterceptor; private View mDetailsLayout; private UnfoldableView mUnfoldableView; private ProgressDialog mLoadingProgressDialog ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_unfoldable_details); mLoadingProgressDialog = ProgressDialog.show(this,"" , "Loading..", true); mLoadingProgressDialog.setCancelable(false); DataUpdaterTask updateTask = new DataUpdaterTask(this); updateTask.execute(); Log.i(Debugger.TAG, "onCreate()"); mListView = (ListView) findViewById(R.id.list_view); mListTouchInterceptor = findViewById(R.id.touch_interceptor_view); mListTouchInterceptor.setClickable(false); mDetailsLayout = findViewById(R.id.details_layout); mDetailsLayout.setVisibility(View.INVISIBLE); mUnfoldableView = (UnfoldableView) findViewById(R.id.unfoldable_view); Bitmap glance = ((BitmapDrawable) getResources().getDrawable(R.drawable.unfold_glance)).getBitmap(); mUnfoldableView.setFoldShading(new GlanceFoldShading(this, glance)); mUnfoldableView.setOnFoldingListener(new UnfoldableView.SimpleFoldingListener() { @Override public void onUnfolding(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(true); mDetailsLayout.setVisibility(View.VISIBLE); } @Override public void onUnfolded(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(false); } @Override public void onFoldingBack(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(true); } @Override public void onFoldedBack(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(false); mDetailsLayout.setVisibility(View.INVISIBLE); } }); ReminderUtil.setOneTimeAlarm(mAlaramManager); } @Override public void onBackPressed() { if (mUnfoldableView != null && (mUnfoldableView.isUnfolded() || mUnfoldableView.isUnfolding())) { mUnfoldableView.foldBack(); } else { super.onBackPressed(); } } public void openDetails(View coverView, PhraseModel phrase) { ImageView image = (ImageView) findViewById(R.id.details_image); TextView title = (TextView) findViewById( R.id.details_title); TextView description = (TextView) findViewById( R.id.details_text); Picasso.with(this).load(phrase.getImageId()).into(image); //Bitmap b=replaceColor(BitmapFactory.decodeResource(getResources(), painting.getImageId()),Color.YELLOW,Color.MAGENTA); //image.setImageBitmap(b); // Bitmap bitmapImage = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888); // // bitmapImage.eraseColor(painting.getImageId()); // // image.setImageBitmap(bitmapImage); title.setText(phrase.getTitle()); description.setText(phrase.getUsagePunjabi() + "\n" + phrase.getUsagePunjabi()); mUnfoldableView.unfold(coverView, mDetailsLayout); } public Bitmap replaceColor(Bitmap src,int fromColor, int targetColor) { if(src == null) { return null; } // Source image size int width = src.getWidth(); int height = src.getHeight(); int[] pixels = new int[width * height]; //get pixels src.getPixels(pixels, 0, width, 0, 0, width, height); for(int x = 0; x < pixels.length; ++x) { pixels[x] = (pixels[x] == fromColor) ? targetColor : pixels[x]; } // create result bitmap output Bitmap result = Bitmap.createBitmap(width, height, src.getConfig()); //set pixels result.setPixels(pixels, 0, width, 0, 0, width, height); return result; } @Override public void callback(PhraseBook phraseBook) { Log.i(Debugger.TAG, "callback()"); displayPhraseData(phraseBook); // Set the adapter on the ListView mListView.setAdapter(new PaintingsAdapter(this)); mLoadingProgressDialog.dismiss(); } private void displayPhraseData(PhraseBook phraseBook) { Log.i(Debugger.TAG, "displayPhraseData()"); if( phraseBook != null){ Log.i(Debugger.TAG, "Size of json phrases : " + phraseBook.getPhraseList().size()); // clear all phrase data PhraseManager.getInstance().getPhraseList().clear(); for( PhraseModel phrase : phraseBook.getPhraseList()){ // save to db PhraseManager.getInstance().addPhrase(0, phrase); }// end for }// end if } }