I have a problem with share facebook link. All the time i click on it says
"Unfortunately, this page is not available. Did you get a broken link or page has been deleted."
public static final String FACEBOOK_SHARE_ACTION_LINK = "https://google.com"; // =)
EdiTED
publishing Image
public class FacebookActivity extends Activity {
private FacebookFacade facebook;
private FacebookEventObserver facebookEventObserver;
private TextView messageView;
private String link;
private String linkName;
private String linkDescription;
private String picture;
private Map<String, String> actionsMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_facebook);
facebook = new FacebookFacade(this, Constants.FACEBOOK_APP_ID);
facebookEventObserver = FacebookEventObserver.newInstance();
messageView = (TextView) findViewById(R.id.message);
TextView linkNameView = (TextView) findViewById(R.id.link_name);
TextView linkDescriptionView = (TextView) findViewById(R.id.link_description);
//Button postButton = (Button) findViewById(R.id.button_post);
Button postImageButton = (Button) findViewById(R.id.button_post_image);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String message = bundle.getString(Extra.POST_MESSAGE);
link = bundle.getString(Extra.POST_LINK);
linkName = bundle.getString(Extra.POST_LINK_NAME);
linkDescription = bundle.getString(Extra.POST_LINK_DESCRIPTION);
picture = bundle.getString(Extra.POST_PICTURE);
actionsMap = new HashMap<String, String>();
actionsMap.put(Constants.FACEBOOK_SHARE_ACTION_NAME, Constants.FACEBOOK_SHARE_ACTION_LINK);
messageView.setText(message);
linkNameView.setText(linkName);
linkDescriptionView.setText(linkDescription);
}
postImageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (facebook.isAuthorized()) {
publishImage();
finish();
} else {
// Start authentication dialog and publish image after successful authentication
facebook.authorize(new AuthListener() {
#Override
public void onAuthSucceed() {
publishImage();
finish();
}
#Override
public void onAuthFail(String error) { // Do noting
}
});
}
}
});
}
//private void publishMessage() {
//facebook.publishMessage(messageView.getText().toString(), link, linkName, linkDescription, picture, actionsMap);
//}
private void publishImage() {
Bitmap bmp = ((BitmapDrawable) getResources().getDrawable(R.drawable.howmuchcanufarm)).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
facebook.publishImage(bitmapdata, Constants.FACEBOOK_SHARE_IMAGE_CAPTION);
}
#Override
public void onStart() {
super.onStart();
facebookEventObserver.registerListeners(this);
if (!facebook.isAuthorized()) {
facebook.authorize();
}
}
#Override
public void onStop() {
facebookEventObserver.unregisterListeners();
super.onStop();
}
}
Related
My app has a post layout which have an edit button and the send button. All i want to do is to show only edit button if current user is viewing his/her post and not the send button. Just like a stackoverflow post, you can't edit other's post and can't send a message to yourself. I have tried boolean methods but still no solution. Thanks.
Activity that have showButtonsForCurrentUser() method ;
public class ViewPostActivity extends AppCompatActivity {
private static final String TAG = "ViewPostActivity";
//widgets
private TextView mTitle, mDescription, mPrice, mLocation;
//vars
private String mPostId;
private String userId;
private Post mPost;
private PostImages mPostImages;
private ViewPager viewPager;
private ImageView editPostIcon;
private WormDotsIndicator wormDotsIndicator;
public ViewAdapter viewAdapter;
public DatabaseReference reference;
public FirebaseUser currentUser;
public ArrayList<String> IMAGES = new ArrayList<>();
public ArrayList<Uri> mImageUris = new ArrayList<>();
private SquareImageView postImageView;
private User user;
//Dialog and Sheet vars
private Dialog deleteDialog;
private Button deleteBtnDialog;
private Button deleteBtnSheet;
private Button updateBtn;
private Button sendBtn;
private TextView titleTv, messageTv;
private ImageView closeIcon;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_post);
mPostId = getIntent().getStringExtra(getString(R.string.arg_post_id));
mTitle = (TextView) findViewById(R.id.post_title);
mDescription = (TextView) findViewById(R.id.post_description);
mPrice = (TextView) findViewById(R.id.post_price);
mLocation = (TextView) findViewById(R.id.post_location);
postImageView = findViewById(R.id.post_image);
sendBtn = findViewById(R.id.send_msg);
viewPager = findViewById(R.id.view_pager_images);
editPostIcon = findViewById(R.id.edit_post_btn);
wormDotsIndicator = findViewById(R.id.dotsindicator);
editPostIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showBottomSheetDialog();
}
});
getPostInfo();
showButtonsForCurrentUser();
////MyPosts Layout/////
deleteBtnDialog = findViewById(R.id.dialog_btn);
deleteDialog = new Dialog(this);
////MyPosts Layout/////
sendBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(ViewPostActivity.this, MessageActivity.class);
intent.putExtra("userId", userId);
startActivity(intent);
}
});
}
public void showButtonsForCurrentUser(){
currentUser = FirebaseAuth.getInstance().getCurrentUser();
//sendBtn and editPostIcon are set to GONE.
if (currentUser.equals(userId)){
sendBtn.setVisibility(View.VISIBLE);
}else{
editPostIcon.setVisibility(View.VISIBLE);
}
}
private void getPostInfo(){
Log.d(TAG, "getPostInfo: getting the post information.");
reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child(getString(R.string.node_posts))
.orderByKey()
.equalTo(mPostId);
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
DataSnapshot singleSnapshot = dataSnapshot.getChildren().iterator().next();
if(singleSnapshot != null){
mPost = singleSnapshot.getValue(Post.class);
Log.d(TAG, "onDataChange: found the post: " + mPost.getTitle());
mTitle.setText(mPost.getTitle());
mDescription.setText(mPost.getDescription());
String price = "FREE";
if(mPost.getPrice() != null){
price = "$" + mPost.getPrice();
}
mPrice.setText(price);
String location = mPost.getCity();
mLocation.setText(location);
userId = mPost.getUser_id();
if (mPost.getImage() != null){
wormDotsIndicator.setVisibility(View.INVISIBLE);
postImageView.setVisibility(View.VISIBLE);
Picasso.get().load(mPost.getImage()).into(postImageView);
}else {
IMAGES = mPost.getPostImages();
for (int i = 0; i <IMAGES.size(); i++){
Uri myUri = Uri.parse(IMAGES.get(i));
mImageUris.add(myUri);
}
viewAdapter = new ViewAdapter(getApplication(), IMAGES);
viewPager.setAdapter(viewAdapter);
wormDotsIndicator.setViewPager(viewPager);
}
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void showBottomSheetDialog() {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(ViewPostActivity.this, R.style.BottomSheetDialogTheme);
LinearLayout linearLayout = findViewById(R.id.bottom_sheet_update_container);
View bottomSheetView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.bottom_sheet_update, linearLayout);
updateBtn = bottomSheetView.findViewById(R.id.update_btnn);
deleteBtnSheet = bottomSheetView.findViewById(R.id.delete_btnn);
bottomSheetDialog.setContentView(bottomSheetView);
bottomSheetDialog.show();
updateBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent updateActivityIntent = new Intent(ViewPostActivity.this, UpdateActivity.class);
if (IMAGES != null){
updateActivityIntent.putStringArrayListExtra("IMAGES", IMAGES);
updateActivityIntent.putParcelableArrayListExtra("IMAGEURIS", mImageUris);
}else {
String singlePhotoUrl = mPost.getImage();
updateActivityIntent.putExtra("Single Photo url", singlePhotoUrl);
}
updateActivityIntent.putExtra("Başlık", mTitle.getText());
updateActivityIntent.putExtra("Açıklama", mDescription.getText());
updateActivityIntent.putExtra("Fiyat", mPrice.getText());
updateActivityIntent.putExtra("mPostId", mPostId);
startActivity(updateActivityIntent);
bottomSheetDialog.dismiss();
}
});
deleteBtnSheet.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showDeleteDialog();
}
});
}
public void showDeleteDialog(){
deleteDialog.setContentView(R.layout.positive_dialog);
closeIcon = deleteDialog.findViewById(R.id.close_dialog);
deleteBtnDialog = deleteDialog.findViewById(R.id.dialog_btn);
titleTv = deleteDialog.findViewById(R.id.titleTv);
messageTv = deleteDialog.findViewById(R.id.message_dialog);
closeIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
deleteDialog.dismiss();
}
});
deleteDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
deleteDialog.show();
deleteBtnDialog.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
deletePost(mPostId);
finish();
overridePendingTransition( 0, 0);
startActivity(getIntent());
overridePendingTransition( 0, 0);
deleteDialog.dismiss();
}
});
}
private void deletePost(String deletePostId){
Bundle args = new Bundle();
args.putString(getString(R.string.arg_post_id), deletePostId);
Query deleteQuery = reference.child("posts").orderByChild("post_id").equalTo(deletePostId);
deleteQuery.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot delData: dataSnapshot.getChildren()){
delData.getRef().removeValue();
Intent backIntent = new Intent(ViewPostActivity.this, SearchActivity.class);
startActivity(backIntent);
}
Toast.makeText(ViewPostActivity.this,"Data Deleted",Toast.LENGTH_LONG).show();
}
#Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(ViewPostActivity.this,databaseError.getMessage(),Toast.LENGTH_LONG).show();
}
});
}
private void status(String status){
currentUser = FirebaseAuth.getInstance().getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("users").child(currentUser.getUid());
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("status", status);
reference.updateChildren(hashMap);
}
#Override
protected void onResume() {
super.onResume();
status("online");
}
#Override
protected void onPause() {
super.onPause();
status("offline");
}
}
what are the values for mPostId?
I would log the userID and currentuser values thats being retrieved, to check if there is no issue your query. The boolean part should work
How to get the data from server and upload data to server using JSON?
please tell me.
This is QRActivity------------------------------------------------
final View.OnClickListener listener = new View.OnClickListener() {
#Override
public
void onClick(View v) {
btnSearch.setClickable(true);
// Server call with record_id
//DistributionDetails detDis <-- response json object from server call
QrActivityViewDetails detDis = new
QrActivityViewDetails(1002,"NORORG147530","No2,abcd Road , Colombo 03","0112233456");
Intent myIntent = new Intent(QrActivity.this, DistributionDetails.class);
myIntent.putExtra("QrActivityViewDetails", detDis);
startActivity(myIntent);
}
};
This is QrActivityViewDetails Class file
public class QrActivityViewDetails implements Serializable {
#SerializedName("DistributionID")
private int DistributionID;
#SerializedName("full_name")
private String full_name;
#SerializedName("full_address")
private String full_address;
#SerializedName("contact")
private String contact;
public QrActivityViewDetails(int DistributionID, String full_name, String full_address, String contact_number)
{
this.DistributionID = DistributionID;
this.full_name = full_name;
this.full_address = full_address;
this.contact = contact_number;
}
public
int getRecord_id() {
return DistributionID;
}
public
void setRecord_id(int record_id) {
this.DistributionID = record_id;
}
public
String getFull_name() {
return full_name;
}
public
void setFull_name(String full_name) {
this.full_name = full_name;
}
public
String getFull_address() {
return full_address;
}
public
void setFull_address(String full_address) {
this.full_address = full_address;
}
public
String getContact() {
return contact;
}
public
void setContact(String contact) {
this.contact = contact;
}
}
This is View Data Activity called DistributionDetails---------------
public class DistributionDetails extends AppCompatActivity {
private QrActivityViewDetails detQRV;
TextView ID ,Address ,name,contact;
Button btnDIR;
#Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_distribution_details);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
ID = (TextView) findViewById(R.id.lblID);
Address = (TextView) findViewById(R.id.lblAddress);
name = (TextView) findViewById(R.id.lblUname);
contact = (TextView) findViewById(R.id.lblTelenum);
btnDIR = (Button) findViewById(R.id.btnDelivered);
IntendFill();
btnDIR.setOnClickListener(new View.OnClickListener() {
#Override
public
void onClick(View v) {
Intent intent = new Intent(DistributionDetails.this, FinalActivity.class);
startActivity(intent);
}
});
}
public void IntendFill() {
Intent intent = getIntent();
if (intent.hasExtra("QrActivityViewDetails")) {
detQRV = (QrActivityViewDetails) intent.getSerializableExtra("QrActivityViewDetails");
ID.setText(String.valueOf(detQRV.getRecord_id()));
Address.setText(String.valueOf(detQRV.getFull_address()));
name.setText(String.valueOf(detQRV.getFull_name()));
contact.setText(String.valueOf(detQRV.getContact()));
}
}
}
I am trying to use RxAndroid to do the same work which is AsyncTask exactly does. I coded a simple example, where I enter a n integer in an edittext and when I press
a button, I make the hread to sleep for 3 seconds using "SystemClock.sleep" and while the thread is sleeping I show a progressbar and when the three seconds
elapsed the progresssbar will adisappear and the value entered in the edittext will be multiplied by 10 and displayed in atextview.
normally, when I use AsyncTask, I show the progressbar in onPreExecute and make it to disappear in onPostExecute. but when I run the below code I receive the
following error:
Only the original thread that created a view hierarchy can touch its views.
how to handle it properly in RxAndroid?
code:
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private EditText mEditTextValueToProcess = null;
private Button mButtonGoAsynchronous = null;
private TextView mTextViewProcessedValue = null;
private ProgressBar mProgressBar = null;
private rx.Observable<String> mAsyncObservable = null;
Subscriber mAsyncSubscriber = new Subscriber<String>() {
#Override
public void onCompleted() {
Log.w(TAG, "onCompleted");
mProgressBar.setVisibility(View.GONE);
}
#Override
public void onError(Throwable e) {
Log.w(TAG, "onError: " + e.getMessage().toString());
mProgressBar.setVisibility(View.GONE);
}
#Override
public void onNext(String o) {
Log.w(TAG, "onNext:->after processing " + o);
mTextViewProcessedValue.setText(o);
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intiViews();
mAsyncObservable = rx.Observable.create(new rx.Observable.OnSubscribe<String>() {
#Override
public void call(Subscriber<? super String> subscriber) {
mProgressBar = (ProgressBar) findViewById(R.id.progressDialog);
mProgressBar.setVisibility(View.VISIBLE);
SystemClock.sleep(3000);
subscriber.onNext("" + Integer.valueOf(mEditTextValueToProcess.getText().toString()) * 10);
subscriber.onCompleted();
}
});
}
private void intiViews() {
mEditTextValueToProcess = (EditText) findViewById(R.id.edittext);
mButtonGoAsynchronous = (Button) findViewById(R.id.button_go_asynchronous);
mTextViewProcessedValue = (TextView) findViewById(R.id.textview_processed_value);
//mProgressBar = (ProgressBar) findViewById(R.id.progressDialog);
mButtonGoAsynchronous.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mAsyncObservable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mAsyncSubscriber);
}
});
}
}
Have you tried
private Observable<String> createObservable(final int number) {
return rx.Observable.create(new rx.Observable.OnSubscribe<String>() {
#Override
public void call(Subscriber<? super String> subscriber) {
SystemClock.sleep(3000);
subscriber.onNext("" + number * 10);
subscriber.onCompleted();
}
});
}
private void intiViews() {
mEditTextValueToProcess = (EditText) findViewById(R.id.edittext);
mButtonGoAsynchronous = (Button) findViewById(R.id.button_go_asynchronous);
mTextViewProcessedValue = (TextView) findViewById(R.id.textview_processed_value);
mProgressBar = (ProgressBar) findViewById(R.id.progressDialog);
mButtonGoAsynchronous.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mProgressBar.setVisibility(View.VISIBLE);
createObservable(Integer.valueOf(mEditTextValueToProcess.getText().toString()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnNext((ignored) -> {
mProgressBar.setVisibility(View.GONE);
})
.subscribe(mAsyncSubscriber);
}
});
}
?
You need to change few things to achieve this. Look at mAsyncSubscriber initialization, onStart() method & progressBar initialization. The reason why you are getting the error is you are initializing & making your progressbar visible in another thread then your UI thread (because you specified this -> subscribeOn(Schedulers.io()).
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private EditText mEditTextValueToProcess = null;
private Button mButtonGoAsynchronous = null;
private TextView mTextViewProcessedValue = null;
private ProgressBar mProgressBar = null;
private rx.Observable<String> mAsyncObservable = null;
Subscriber mAsyncSubscriber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intiViews();
mAsyncSubscriber = new Subscriber<String>() {
// Override onStart method
#Override
public void onStart() {
mProgressBar.setVisibility(View.VISIBLE);
}
#Override
public void onCompleted() {
Log.w(TAG, "onCompleted");
mProgressBar.setVisibility(View.GONE);
}
#Override
public void onError(Throwable e) {
Log.w(TAG, "onError: " + e.getMessage().toString());
mProgressBar.setVisibility(View.GONE);
}
#Override
public void onNext(String o) {
Log.w(TAG, "onNext:->after processing " + o);
mTextViewProcessedValue.setText(o);
}
};
mAsyncObservable = rx.Observable.create(new rx.Observable.OnSubscribe<String>() {
#Override
public void call(Subscriber<? super String> subscriber) {
SystemClock.sleep(3000);
subscriber.onNext("" + Integer.valueOf(mEditTextValueToProcess.getText().toString()) * 10);
subscriber.onCompleted();
}
});
}
private void intiViews() {
// Init your progressbar
mProgressBar = (ProgressBar) findViewById(R.id.progressDialog);
mEditTextValueToProcess = (EditText) findViewById(R.id.edittext);
mButtonGoAsynchronous = (Button) findViewById(R.id.button_go_asynchronous);
mTextViewProcessedValue = (TextView) findViewById(R.id.textview_processed_value);
//mProgressBar = (ProgressBar) findViewById(R.id.progressDialog);
mButtonGoAsynchronous.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mAsyncObservable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mAsyncSubscriber);
}
});
}
I have a fragment where a user takes a picture with camera and then its uploaded to Firebase. I encode the image into a string with no issues. I see the converted image string in my Firebase console. The issue I have is when decoding the image string from Firebase to display as an Image in a recyclerview nothing displays.
If you can help me understand what my issue is and how to correct it I would really appreciated it. I have been trying to figure this out for 3 days by reading other Stackexchange post and I cant figure out where my issue is.
Thanks.
My Fragment:
public class AddImageFragment extends Fragment {
public static final int REQUEST_IMAGE_CAPTURE = 111;
private EditText progressDetail;
private Button cameraButton;
private Button saveButton;
private Button cancelButton;
private ImageView capturedImage;
private DatabaseReference mDatabaseReference;
public ImageProgress mImageProgress;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.add_image_fragment, container, false);
progressDetail = (TextInputEditText) v.findViewById(R.id.progressStatusEditText);
capturedImage = (ImageView) v.findViewById(R.id.capturedImageView);
cameraButton = (Button) v.findViewById(R.id.takePictureButton);
saveButton = (Button) v.findViewById(R.id.saveButton);
cameraButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openCamera();
}
});
//initialize firebase database
mDatabaseReference = FirebaseDatabase.getInstance().getReference();
saveButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//get current user
FirebaseUser user =FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
try {
Bitmap image = decodeFromFirebaseBase64(mImageProgress.getImageUrl());
capturedImage.setImageBitmap(image);
}catch (IOException e){
e.printStackTrace();
}
myNewImage(uid, progressDetail.getText().toString(),capturedImage.toString());
getActivity().onBackPressed();
}
});
return v;
}
private void myNewImage(String uid, String progressDetails, String imageUrl) {
ImageProgress imageProgress = new ImageProgress(progressDetails, imageUrl);
mDatabaseReference.child("Progress").child(uid).child("Images").push().setValue(imageProgress);
}
private void openCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == getActivity().RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
capturedImage.setImageBitmap(imageBitmap);
encodeBitmapAndSaveToFirebase(imageBitmap);
}
}
public void encodeBitmapAndSaveToFirebase(Bitmap bitmap) {
//current user
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
String imageEncoded = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
reference.child("Progress").child(uid).child("imageUrl").push().setValue(imageEncoded);
}
public static Bitmap decodeFromFirebaseBase64(String image) throws IOException {
byte[] decodeByteArray = android.util.Base64.decode(image, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(decodeByteArray, 0, decodeByteArray.length);
}
}
Activity
public class WeightProgressActivity extends BaseActivity {
public ImageProgress mImageProgress;
private FloatingActionButton fab;
ScaleAnimation shrinkAnim;
private RecyclerView mRecyclerView;
private LinearLayoutManager mLayoutManager;
public ImageView capturedImage;
//firebase database reference
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference mDatabaseReference = database.getReference();
//get current user
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.weight_progress);
setNavDrawer(new MainNavDrawer(this));
//initialize recyclerview
mRecyclerView = (RecyclerView)findViewById(R.id.recyclerView);
shrinkAnim = new ScaleAnimation(1.15f, 0f, 1.15f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
if(mRecyclerView != null){
mRecyclerView.setHasFixedSize(true);
}
//using linearlayout manager in recyclerview
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
//firebaserecycleradapter (firebase ui)
FirebaseRecyclerAdapter<ImageProgress, ImageViewHolder> adapter = new FirebaseRecyclerAdapter<ImageProgress, ImageViewHolder>(
ImageProgress.class, R.layout.weight_progress_list, ImageViewHolder.class, mDatabaseReference.child("images").child(uid).
child("Progress Images").getRef()
) {
#Override
protected void populateViewHolder(ImageViewHolder viewHolder, ImageProgress model, int position) {
viewHolder.progressDetail.setText(model.getProgressDetail());
try {
Bitmap image = decodeFromFirebaseBase64(mImageProgress.getImageUrl());
viewHolder.capturedImage.setImageBitmap(image);
}catch (IOException e){
e.printStackTrace();
}
}
};
mRecyclerView.setAdapter(adapter);
fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_container,
new AddImageFragment()).addToBackStack(null).commit();
//animation to make actionbar disappear
shrinkAnim.setDuration(400);
fab.setAnimation(shrinkAnim);
shrinkAnim.start();
shrinkAnim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//changing floating actionbar visibility to gone on animation end
fab.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
}
});
}
//on back press code
#Override
public void onBackPressed() {
super.onBackPressed();
if (fab.getVisibility() == View.GONE)
fab.setVisibility(View.VISIBLE);
}
//weightViewHolder method
public static class ImageViewHolder extends RecyclerView.ViewHolder{
EditText progressDetail;
ImageView capturedImage;
public ImageViewHolder(View v){
super(v);
progressDetail = (EditText) v.findViewById(R.id.progressStatusEditText);
capturedImage = (ImageView) v.findViewById(R.id.capturedImageView);
}
}
public static Bitmap decodeFromFirebaseBase64(String image) throws IOException {
byte[] decodeByteArray = android.util.Base64.decode(image, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(decodeByteArray, 0, decodeByteArray.length);
}
}
I have MainActivity with two String variables viz. filename & url.
I tried to use one download manager.
I dont know how to pass filename String from my Player Activity.
buttondownload = (TextView )findViewById(R.id.download);
buttondownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DownloadHelper.addNewTask(Player.this, url,
new PreDownloadStatusListener() {
#Override
public void notFoundSDCard(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "No SD Card", Toast.LENGTH_SHORT).show();
}
#Override
public void sdCardCannotWriteOrRead(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Not read and write SD card", Toast.LENGTH_SHORT).show();
}
#Override
public void moreTaskCount(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Task list is full", Toast.LENGTH_SHORT).show();
}
});
Intent intent1 = new Intent(Player.this, DownloadListActivity.class);
startActivity(intent1);
}
});
DownloadHelper.startAllTask(Player.this);
mReceiver = new DownloadReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(DownloadValues.Actions.BROADCAST_RECEIVER_ACTION);
registerReceiver(mReceiver, filter);
They call filename from another public class DownloadUtils.. How can i pass filname to DownloadUtils
I want Pass String from Player to ViewHolder.java
package com.download.main;
public class ViewHolder {
public static final int KEY_URL = 0;
public static final int KEY_SPEED = 1;
public static final int KEY_PROGRESS = 2;
public static final int KEY_IS_PAUSED = 3;
public TextView titleText;
public ProgressBar progressBar;
public TextView speedText;
public ImageButton pauseButton;
public ImageButton deleteButton;
public ImageButton continueButton;
private boolean hasInited = false;
public ViewHolder(View parentView) {
if (parentView != null) {
titleText = (TextView) parentView.findViewById(R.id.title);
speedText = (TextView) parentView.findViewById(R.id.speed);
progressBar = (ProgressBar) parentView.findViewById(R.id.progress_bar);
pauseButton = (ImageButton) parentView.findViewById(R.id.btn_pause);
deleteButton = (ImageButton) parentView.findViewById(R.id.btn_delete);
continueButton = (ImageButton) parentView.findViewById(R.id.btn_continue);
hasInited = true;
}
}
public static HashMap<Integer, String> getItemDataMap(String url, String speed, String progress, String isPaused) {
HashMap<Integer, String> item = new HashMap<Integer, String>();
item.put(KEY_URL, url);
item.put(KEY_SPEED, speed);
item.put(KEY_PROGRESS, progress);
item.put(KEY_IS_PAUSED, isPaused);
return item;
}
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}
public void onPause() {
if (hasInited) {
pauseButton.setVisibility(View.GONE);
continueButton.setVisibility(View.VISIBLE);
}
}
public void setData(String url, String speed, String progress) {
setData(url, speed, progress, false + "");
}
public void setData(String url, String speed, String progress, String isPaused) {
if (hasInited) {
HashMap<Integer, String> item = getItemDataMap(url, speed, progress, isPaused);
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(speed);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(item.get(KEY_PROGRESS)));
}
}
}
}
To pass any data from one activity to another use Intent. Example:-
Use below code in your Player.java class:-
Intent intent = new Intent(FromClass.this, ToClass.class);
intent.putExtra("filename", filename);
startActivity(intent);
Write the below code in the ViewHolder.java class:-
do not forget to extend Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutName);
Intent intent = getIntent();
String filename= intent.getStringExtra("filename");
}
Then you can use filename in your setData() like this:-
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(filename);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}