|
| 1 | +package io.spaceapi.community.myhackerspace; |
| 2 | + |
| 3 | +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 4 | +import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 5 | + |
| 6 | +import android.Manifest; |
| 7 | +import android.content.Context; |
| 8 | +import android.content.Intent; |
| 9 | +import android.net.Uri; |
| 10 | +import android.util.AttributeSet; |
| 11 | +import android.view.LayoutInflater; |
| 12 | +import android.view.View; |
| 13 | +import android.view.ViewGroup; |
| 14 | +import android.widget.Button; |
| 15 | +import android.widget.LinearLayout; |
| 16 | +import android.widget.TextView; |
| 17 | + |
| 18 | +import androidx.annotation.Nullable; |
| 19 | + |
| 20 | +public class AboutLayout extends LinearLayout { |
| 21 | + |
| 22 | + public AboutLayout(Context context) { |
| 23 | + super(context); |
| 24 | + } |
| 25 | + |
| 26 | + public AboutLayout(Context context, @Nullable AttributeSet attrs) { |
| 27 | + super(context, attrs); |
| 28 | + } |
| 29 | + |
| 30 | + public AboutLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
| 31 | + super(context, attrs, defStyleAttr); |
| 32 | + } |
| 33 | + |
| 34 | + public AboutLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 35 | + super(context, attrs, defStyleAttr, defStyleRes); |
| 36 | + } |
| 37 | + |
| 38 | + public void init() { |
| 39 | + Button openRepoButton = findViewById(R.id.about_open_repo_button); |
| 40 | + openRepoButton.setOnClickListener(new OnClickListener() { |
| 41 | + @Override |
| 42 | + public void onClick(View v) { |
| 43 | + TextView repository = (TextView)findViewById(R.id.about_repository); |
| 44 | + String url = (String) repository.getText(); |
| 45 | + openWebPage(url); |
| 46 | + } |
| 47 | + }); |
| 48 | + TextView version = findViewById(R.id.about_version_text); |
| 49 | + version.setText(BuildConfig.VERSION_NAME + " (" + Integer.toString(BuildConfig.VERSION_CODE) + ")"); |
| 50 | + } |
| 51 | + |
| 52 | + public static AboutLayout create(Context context) { |
| 53 | + // use xml layout, see https://stackoverflow.com/a/13889257 |
| 54 | + LayoutInflater layoutInflater = LayoutInflater.from(context); |
| 55 | + AboutLayout about = (AboutLayout) layoutInflater.inflate(R.layout.about, null, false); |
| 56 | + about.init(); |
| 57 | + return about; |
| 58 | + } |
| 59 | + |
| 60 | + public void openWebPage(String url) { |
| 61 | + // from https://stackoverflow.com/a/43981160 |
| 62 | + Uri webpage = Uri.parse(url); |
| 63 | + |
| 64 | + Intent intent = new Intent(Intent.ACTION_VIEW, webpage); |
| 65 | + |
| 66 | + if (intent.resolveActivity(getContext().getPackageManager()) != null) { |
| 67 | + getContext().startActivity(intent); |
| 68 | + }else{ |
| 69 | +//Page not found |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments