Locating style animation for ImageView - android

I'm trying to create an animation for an ImageView which shows like picture below (collected on Stackoverflow).
I want to do this because I want it shows when my location is locating. I've tried to find keywords but i couldn't found anything. Thanks.

You can use Wavedrawable Library.
it is available in GitHub with sample projects.
https://github.com/Alexrs95/WaveDrawable
compile 'me.alexrs:wave-drawable:1.0.0'
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import me.alexrs.wavedrawable.WaveDrawable;
public class MainActivity extends Activity {
private WaveDrawable waveDrawable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) findViewById(R.id.image);
waveDrawable = new WaveDrawable(Color.parseColor("#8e44ad"), 500);
imageView.setBackgroundDrawable(waveDrawable);
interpolator = new LinearInterpolator();
waveDrawable.setWaveInterpolator(interpolator);
waveDrawable.startAnimation();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Related

Android create clickable email link programmatically

I want to create an email link in an Android app.
If I do it this way:
<TextView
android:text="xxxx#yyyy.zz"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:autoLink="email"/>
Then it works as it should.
I do, however, want to do it in code. The following example is a new Android project in Android Studio with a basic activity. I have added the marked code and added the id "mytest" to the auto-generated layout.
package com.example.bjursus.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.util.Linkify;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Added code - start
getIntent().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ConstraintLayout clo = (ConstraintLayout) findViewById(R.id.mytest);
TextView tv = new TextView(getApplicationContext());
tv.setText("zxxx#yyyy.zz");
Linkify.addLinks(tv, Linkify.EMAIL_ADDRESSES);
tv.setLinksClickable(true);
clo.addView(tv);
// Added code - end
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This will give me the email link, but when I click it I get this exception:
AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Any suggestions?
Simply add this to the code
getIntent().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
This will tell your activity it is okay to start a new task.

app chrashing on imageview rotation

Hi guys i am new on android developing and i am trying to rotate an imageview.
The problem comes when (obviously) i push the button and the app close itself
Code java:
package comad.exampleaaaa.vittoriodaadntico.bottiglia3;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity6 extends AppCompatActivity {
public ImageView bottiglia;
public Button gira;
#Override
protected void onCreate(Bundle savedInstanceState) {
gira=(Button)findViewById(R.id.btn_roll);
bottiglia=(ImageView)findViewById(R.id.bottiglia);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
}
public void rollOnClick(View v){
RotateAnimation anim=new RotateAnimation(0,360,20,20,20,20);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
bottiglia.startAnimation(anim);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity6, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
error log :
http://imgur.com/H2Phsvf
You call methods in wrong order:
#Override
protected void onCreate(Bundle savedInstanceState) {
gira=(Button)findViewById(R.id.btn_roll); // This
bottiglia=(ImageView)findViewById(R.id.bottiglia); // And this
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6); // Should come after this
}
Here you search for views before you set content view. You should set your view, and only then search for widgets. Otherwise there is no view in which your widgets could be found, so both gira and bottiglia are nulls:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
gira=(Button)findViewById(R.id.btn_roll);
bottiglia=(ImageView)findViewById(R.id.bottiglia);
}

SharedPreference values not available between activities

I have 2 activities. One is the main activity. One is the Preference activity. I'm trying to change the background color of the activity based on the color selected in a RadioGroup in the Preference activity.
This is the class file for the main activity.
package com.example.mycsimodules;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ArrayAdapter;
public class ModList extends ActionBarActivity {
SharedPreferences savedData;
private String[] moduleArray = { "COMP 41600", "COMP 41620", "COMP 47330","COMP 30160", "COMP 30500", "COMP 40725", "COMP 41100", "COMP 41110" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mod_list);
savedData=getSharedPreferences("MyPrefs",0);
String colorMine=savedData.getString("color", "deflt");
TextView head=(TextView) findViewById(R.id.mymodlist);
head.setText(colorMine);
ArrayAdapter<String> moduleAdapter = new ArrayAdapter<String>(this, R.layout.activity_list_view, R.id.list1, moduleArray);
final ListView list = (ListView) findViewById(R.id.mod_list);
list.setAdapter(moduleAdapter);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.mod_list, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent i=new Intent(this, Preferences.class);
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
This is the class file for the Preference class.
package com.example.mycsimodules;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class Preferences extends ActionBarActivity implements OnClickListener{
RadioGroup colorList;
Button saveButton;
SharedPreferences savedData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
colorList=(RadioGroup) findViewById(R.id.colorRadioGroup);
saveButton=(Button) findViewById(R.id.bSave);
saveButton.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.preferences, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#SuppressLint("NewApi") #Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==saveButton){
RadioButton myColor=(RadioButton) findViewById(colorList.getCheckedRadioButtonId());
String colorSelected=myColor.getText().toString();
TextView label=(TextView) findViewById(R.id.the_color_is);
label.setText(colorSelected);
savedData=getSharedPreferences("MyPref", 0);
SharedPreferences.Editor editor=savedData.edit();
editor.putString("color", colorSelected);
editor.apply();
editor.commit();
}
}
}
I haven't actually done the background color part. I'm just trying to display the value in a TextView currently. But it shows only the default value all the time. What I'm trying to do is.
Click on Settings.
Click on RadioButton for color desired.
Click on Save button.
Click on back key to return to main activity.
I'm pretty new to this and might be doing something wrong. But I just can't figure out what it is.
savedData=getSharedPreferences("MyPrefs",0);
it's diferent from
savedData=getSharedPreferences("MyPref", 0);
Use the same file when you open your SharedPreferences

Android Switch widget force close

Trying to create a switch in android with default ON state and with OnCheckedChangeListener. But application is force closing. What is wrong? please help. New in android development.
package com.tiumca2013.smarthousecontrol;
import android.app.Activity;
import android.app.Fragment;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.Toast;
public class MainActivity extends Activity{
private Switch switch1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
switch1 = (Switch) findViewById(R.id.Switch1);
switch1.setChecked(true); // force close
switch1.setOnCheckedChangeListener(new OnCheckedChangeListener() // force close again
{
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
Toast.makeText(getApplicationContext(),"switch 1 ON",Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(),"switch 1 OFF",Toast.LENGTH_SHORT).show();
}
});
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}

Android Fragement Activity

I dont know what happen with my sdk and eclipse. I install google services,it is install successfully but now i add activity to my old project but now .java file is extends FragementActivity. i dont know why this is happen. Please give reply please.
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class WebViewActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.web_view, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}

Categories

Resources