public void MyButtonClick(View view) {
int count = gridView.getChildCount();
for (int i = 0; i < count; i++) {
View cell = gridView.getChildAt(i);
TextView cellText = (TextView) cell.findViewById(R.id.textpart);
cellText.setTextColor(Color.parseColor("#FF0033"));
}
}
public class MainActivity extends Activity {
private GridView gridView;
private ImageTextAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new ImageTextAdapter(this);
gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(gridViewOnItemClickListener);
}
private GridView.OnItemClickListener gridViewOnItemClickListener = new GridView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // пожалуйста, не комментируйте код так:
// Sending image id to FullScreenActivity
//Intent i = new Intent(getApplicationContext(),
// FullImageActivity.class);
// passing array index
//i.putExtra("id", position);
//startActivity(i);
}
};
public void MyButtonClick(View view) { // нарушение Code Convention в имени метода
int count = gridView.getChildCount();
for (int i = 0; i < count; i++) {
View cell = gridView.getChildAt(i);
TextView cellText = (TextView) cell.findViewById(R.id.textpart);
cellText.setTextColor(Color.parseColor("#FF0033"));
}
}
}
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageTextAdapter(this));
gridview.setOnItemClickListener(gridviewOnItemClickListener);
}
private GridView.OnItemClickListener gridviewOnItemClickListener = new GridView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
// Sending image id to FullScreenActivity
//Intent i = new Intent(getApplicationContext(),
// FullImageActivity.class);
// passing array index
//i.putExtra("id", position);
//startActivity(i);
}
};
public void MyButtonClick(View view)
{
View cell = findViewById(R.layout.cellgrid);
TextView cellText = cell.findViewById(R.id.textpart);
cellText.setTextColor(Color.parseColor("#000000"));
}
}
но можно увеличить до Java 8 с помощью сторонних библиотек
private URI mImageUri;
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo;
try
{
// место где хранятся фото
photo = this.createTemporaryFile("picture", ".jpg");
photo.delete();
}
catch(Exception e)
{
Log.v(TAG, "Не получилось создать фото!");
Toast.makeText(activity, "Пожалуйста, проверьте Sd - карту", 10000);
return false;
}
mImageUri = Uri.fromFile(photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
//вызываем Intent камеры
activity.startActivityForResult(this, intent, MenuShootImage);
private File createTemporaryFile(String part, String ext) throws Exception
{
File tempDir= Environment.getExternalStorageDirectory();
tempDir=new File(tempDir.getAbsolutePath()+"/.temp/");
if(!tempDir.exists())
{
tempDir.mkdir();
}
return File.createTempFile(part, ext, tempDir);
}
imageUri
:public void grabImage(ImageView imageView)
{
this.getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
Bitmap bitmap;
try
{
bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
imageView.setImageBitmap(bitmap);
}
catch (Exception e)
{
Toast.makeText(this, "Ошибка загрузки", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Ошибка загрузки", e);
}
}
//вызов камеры после выполнения
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if(requestCode==MenuShootImage && resultCode==RESULT_OK)
{
ImageView imageView;
//делаем, что нужно с картинкой
this.grabImage(imageView);
}
super.onActivityResult(requestCode, resultCode, intent);
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application>
...
</application>
/ Storage Permissions
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
/**
* Checks if the app has permission to write to device storage
*
* If the app does not has permission then the user will be prompted to grant permissions
*
* @param activity
*/
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
}
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.M){
} else{
}
Xml - файл Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="android.letscoder.xyz.videosolution.MainActivity">
<VideoView
android:id="@+id/video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Код класса Activity:
package android.letscoder.xyz.videosolution;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
VideoView mVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupVideoView(mVideoView, "http://techslides.com/demos/sample-videos/small.mp4");
}
private void setupVideoView(VideoView videoView, String url) {
videoView = (VideoView) findViewById(R.id.video_view);
MediaController controls = new MediaController(this);
controls.setAnchorView(videoView);
videoView.setMediaController(controls);
videoView.setVideoURI(Uri.parse(url));
videoView.start();
}
}
Не забудьте прописать permisson в манифесте:
<uses-permission android:name="android.permission.INTERNET"/>
Всё работает:
currentTime
в интерфейсе класса и создаём геттер к нему:public class TimerClass extends CountDownTimer {
public String getCurrentTime() {
return currentTime;
}
private String currentTime;
public TimerClass(long milliFuture, long interval) {
super(milliFuture, interval);
}
@Override
public void onTick(long millisUntilFinished) {
long millis = millisUntilFinished;
String hhmmss = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
currentTime = hhmmss;
}
@Override
public void onFinish() {
currentTime = "Completed";
}
}
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
TextView mTimer;
Button startButton, pauseButton;
int timeToEnd = 25000;
final TimerClass timer = new TimerClass(timeToEnd, 1000);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTimer = (TextView) findViewById(R.id.tv);
startButton = (Button) findViewById(R.id.startButton);
pauseButton = (Button) findViewById(R.id.pauseButton);
startButton.setOnClickListener(this);
pauseButton.setOnClickListener(this);
runTimer();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.startButton:
startButton.setOnClickListener(this);
timer.start();
break;
case R.id.pauseButton:
pauseButton.setOnClickListener(this);
timer.cancel();
}
}
private void runTimer() {
final Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
mTimer.setText(timer.getCurrentTime());
handler.post(this);
}
});
}
}
выложить в Google Play,
Uri imageUri = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + "image");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Text");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
java se на среднем уровне