Some Useful Codes For Sketchware
Download Sketchware
Jave Codes For Sketchware
1. Title Of Action Bar
getActionBar().setTitle("Title");
2. Subtitle Of Action Bar
getActionBar().setSubtitle("Subtitle");
3. Icon On Action Bar
getActionBar().setIcon(r.drawable.icon_name);
4. Choose Image As Background
} private static int RESULT_LOAD_IMAGE = 1;
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData();
try {
java.io.InputStream is = getContentResolver().openInputStream(selectedImage);
android.graphics.drawable.Drawable bg_img = android.graphics.drawable.Drawable.createFromStream(is, selectedImage.toString());
imageview1.setBackground(bg_img); }
catch (java.io.FileNotFoundException e) {
showMessage(e.toString());
} }
//imageview1 onClick
Intent i = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
5. Tabs Layout
viewPager = new android.support.v4.view.ViewPager(this);
viewPager.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
MyPagerAdapter adapter = new MyPagerAdapter();
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(0);
base.addView(viewPager);
tabLayout = new android.support.design.widget.TabLayout(this);
tabLayout.setTabG ravity(tabLayout.GRAVITY_FILL);
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#000000"));
///You can change tab underline(indicator) color
from here
tabLayout.setTabTextColors(Color.parseColor("#00ffffff"),///Tab color when not selected Color.parseColor("#000000"));///Tab color when selected
///You can change tab text color from here
final int[ ] tabIcons = {
R.drawable.ic_1,
R.drawable.ic_2,
R.drawable.ic_3,
R.drawable.ic_4
};
///here ic_1, ic_2, etc. are the names of icons which you added in image manager
tabLayout.setupWithViewPager(viewPager);
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
tabLayout.getTabAt(3).setIcon(tabIcons[3]);
cod.addView(tabLayout);
}
private class MyPagerAdapter extends android.support.v4.view.PagerAdapter {
public int getCount() {
return 4;
}
@Override public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.empty, null);
LinearLayout container = (LinearLayout) v.findViewById(R.id.linear1);
if (position == 0) {
ViewGroup parent = (ViewGroup) layout1.getParent();
if (parent != null) {
parent.removeView(layout1);
}container.addView(layout1);
} else if (position == 1) {
ViewGroup parent = (ViewGroup) layout2.getParent();
if (parent != null) {
parent.removeView(layout2);
}
container.addView(layout2);
} else if (position == 2) {
ViewGroup parent = (ViewGroup) layout3.getParent();
if (parent != null) {
parent.removeView(layout3);
}
container.addView(layout3);
} else if (position == 3) {
ViewGroup parent = (ViewGroup) layout4.getParent();
if (parent != null) {
parent.removeView(layout4);
}
container.addView(layout4);
}
collection.addView(v, 0);
return v;
}
@Override public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
trash.addView((View) view);
}
@Override public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "HOME";
case 1:
return "SETTINGS";
case 2:
return "PROFILE";
case 3:
return "MUSIC";
default:
return null;
}
///you can change the name of tabs from HOME, SETTINGS, PROFILE, etc you want to
}
@Override public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);}
@Override public Parcelable saveState() {
return null;
}
}
android.support.v4.view.ViewPager viewPager;
android.support.design.widget.TabLayout tabLayout;
private void foo() {
///add 4 linearV with height=WRAP_CONTENT and width = MATCH_PARENT and name that linears id (layout1, layout2, layout3, layout4)
///add 2 linearV or H with height and width = WRAP_CONTENT and name their id (base and trash)
///add one more linearH on the topp of all linear and name its id (cod), it will show yout tabs
///base and trash should be set in between cod and that 4 linears
///add anything to that 4 linear will show in the screen as different when particular tab will be clicked
///now add a custom layout (empty) and add a linear V or H with height and width = MATCH_PARENT
6. Spinner In Action Bar
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
// Add List
menu.add("Menu")
.setIcon(R.drawable.ic_chat_white);
return true;
}
@Override
public boolean onOptionsItemSelected(final MenuItem item){
switch (item.getTitle().toString()) {
case "Menu":
showMessage("Clicked");
return true;
default:
return super.onOptionsItemSelected(item);
}
7. Tab Target View
//To Use
//_view
//_title
//_msg
//_bgcolor
TapTargetView.showFor(MainActivity.this,
TapTarget.forView(_view, _title, _msg)
.outerCircleColorInt(Color.parseColor(_bgcolor))
.outerCircleAlpha(0.96f)
.targetCircleColorInt(Color.parseColor("#FFFFFF"))
.titleTextSize(25)
.titleTextColorInt(Color.parseColor("#FFFFFF"))
.descriptionTextSize(18)
.descriptionTextColor(android.R.color.white)
.textColorInt(Color.parseColor("#FFFFFF"))
.textTypeface(Typeface.SANS_SERIF)
.dimColor(android.R.color.black)
.drawShadow(true)
.cancelable(true)
.tintTarget(true)
.transparentTarget(true)
//.icon(Drawable)
.targetRadius(60),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
}
});
8. Listview - Swipe Refresh
final android.support.v4.widget.SwipeRefreshLayout sl = new android.support.v4.widget.SwipeRefreshLayout(MainActivity.this);
sl.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.MATCH_PARENT));
linear1.addView(sl);
linear1.removeView(listview1);
sl.addView(listview1);
sl.setOnRefreshListener( new android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { _refresh(); } } );
9. Share On Social Network
try{
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Текст сообщения");
sharingIntent.setPackage("com.whatsapp");
startActivity(sharingIntent);
} catch (Exception e) {
Toast.makeText(getActivity(),"Приложение не установлено",Toast.LENGTH_SHORT).show();
}
/*Текст сообщения можно заменить, а вместо com.whatsapp вы можете подставить почти любое приложение.
Вот несколько вариантов:
* com.vkontakte.android - ВКонтакте
* com.whatsapp - WhatsApp
* com.facebook.katana - Facebook
* org.telegram.multi - Multigram
* org.tel+gram.messenger - Tеl+grаm
* advanced.twitter.android - Twitter
* com.google.android.apps.plus - Google+
*/
10. Firebase Email Verification
FirebaseAuth auth = FirebaseAuth.getInstance();
com.google.firebase.auth.FirebaseUser user =
auth.getCurrentUser();
user.sendEmailVerification().addOnCompleteListener
(new
OnCompleteListener<Void>()
{ @Override
public void onComplete(Task task)
{ if (task.isSuccessful()) {
} else {
}
}});
Thanks Regards Happy Graphics Team.
No comments:
Post a Comment