Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open about box with a button #44

Closed
Kvaibhav01 opened this issue Nov 1, 2017 · 9 comments
Closed

Open about box with a button #44

Kvaibhav01 opened this issue Nov 1, 2017 · 9 comments

Comments

@Kvaibhav01
Copy link

I would like to implement the about activity only when the user taps an icon of about (or in a drop-down-the three dots menu) in app bar. How to implement that?

@mikemee
Copy link
Collaborator

mikemee commented Nov 2, 2017

There's nothing special here. It's all standard Android. E.g. you can use standard Android style menus for the launch button, e.g. something like this to setup the menu item (with icon etc):

        MenuInflater menuInflater = activity.getMenuInflater();
        menuInflater.inflate(R.menu.about_screen_menu, menu);

and then launch it with:

            case R.id.open_about:
                AboutActivity.launch(activity);
                return true;

@mikemee mikemee closed this as completed Nov 2, 2017
@Kvaibhav01
Copy link
Author

Thank you for that but I'm a bit confused here.

  1. Do I need to create a new java file for implementing this? (It will contain all the code from the setup part).
  2. How do I add an icon for this in my menu bar?

@mikemee
Copy link
Collaborator

mikemee commented Nov 3, 2017

@Kvaibhav01 I'm afraid these are Android programming questions and really don't have much to do with this library. I'd love to help more, but there are plenty of references for this elsewhere. Good luck!

@Kvaibhav01
Copy link
Author

Kvaibhav01 commented Nov 3, 2017

So I added the relevant code to do this as:

  1. Added a new <item> in menu.xml
  2. Copied all the code of this library to a new java file named AboutActivity.java
  3. Added the following code in my MainActivity.java file in onOptionsItemSelected method:
if (id == R.id.action_about) {
            Intent intent = new Intent(this, AboutActivity.class);
            startActivity(intent);
            return true;
        }
  1. Updated the manifest by:

<activity android:name=".AboutActivity"></activity>

But when I run the app on emulator, it shows up the following screen when the action_about icon is tapped:

alt text

I have already added more informations like acknowledgements, privacy policy et cetera but it's showing something weird!

@mikemee
Copy link
Collaborator

mikemee commented Nov 3, 2017

I setup AboutActivity in the initial app startup. Then, later in the app, I access it. That way, it's all configured and ready to go.

I.e. like this:

public class LogicApp extends android.app.Application {
....
   @Override
    public void onCreate() {
        super.onCreate();
...

        initAboutBox();
     }
...
    public void initAboutBox() {
        final AboutConfig aboutConfig = AboutConfig.getInstance();
        aboutConfig.appName = getString(R.string.app_name);
        aboutConfig.appIcon = R.mipmap.ic_launcher;
        aboutConfig.version = BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")";
        aboutConfig.aboutLabelTitle = getString(R.string.about_egghead_games);
        aboutConfig.packageName = getApplicationContext().getPackageName();
        aboutConfig.buildType = "google".equalsIgnoreCase(BuildConfig.FLAVOR_appstore)
                ? AboutConfig.BuildType.GOOGLE : AboutConfig.BuildType.AMAZON;

        aboutConfig.logUiEventName = LOG_UI_EVENT_NAME;
        aboutConfig.facebookUserName = FACEBOOK_USER_NAME;
        aboutConfig.twitterUserName = TWITTER_USER_NAME;
        aboutConfig.webHomePage = WEB_HOME_PAGE;
        aboutConfig.appPublisher = APP_PUBLISHER;
        aboutConfig.guideHtmlPath = GUIDE_HTML_PATH;
        aboutConfig.companyHtmlPath = COMPANY_HTML_PATH;
        aboutConfig.privacyHtmlPath = PRIVACY_HTML_PATH;
        aboutConfig.acknowledgmentHtmlPath = ACKNOWLEDGMENT_HTML_PATH;

        aboutConfig.emailAddress = EMAIL_ADDRESS;
        aboutConfig.emailSubject = getResources().getString(R.string.app_name) + " Question";
        aboutConfig.emailBody = "";
        aboutConfig.shareMessage = getString(R.string.share_message);
        aboutConfig.sharingTitle = getString(R.string.sharing_title);

        aboutConfig.dialog = new IDialog() {
            @Override
            public void open(AppCompatActivity appCompatActivity, String url, String tag) {
                GuideDialog guideDialog = GuideDialog.createDialog(url, tag, true);
                guideDialog.show(appCompatActivity.getSupportFragmentManager(), tag);
            }
        };
    }

And then I can call it with the code I shared above, i.e.

AboutActivity.launch(activity);

Hope this helps!

@mikemee
Copy link
Collaborator

mikemee commented Nov 3, 2017

Take a look at the source code, after you've setup with AboutConfig as shown above, you need to call AboutActivity.launch(yourActivity). This code that is already in the library will then do what you're doing above:

    public static void launch(Activity activity) {
        Intent intent = new Intent(activity, AboutActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        activity.startActivity(intent);
    }

See https://github.com/eggheadgames/android-about-box/blob/master/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java

@Kvaibhav01
Copy link
Author

Everything is going good, I implemented the above. One thing, every time I open the app the about activity launches instead of main activity. How to solve this? I don't wan't my app users to see the about page every time they open the app, it's quite annoying.

@mikemee
Copy link
Collaborator

mikemee commented Nov 5, 2017

after you've setup with AboutConfig as shown above, you need to call AboutActivity.launch(yourActivity)

Sorry, I didn't mean immediately call AboutActivity.launch.

In the app startup, ONLY do the configuration. Later, when they tap the button, THEN call ``AboutActivity.launch(activity)`.

I.e. it is two separate things: configure at app startup, then launch when the user requests it.

Good luck!

@mikemee mikemee reopened this Nov 5, 2017
@mikemee mikemee closed this as completed Nov 5, 2017
@Kvaibhav01
Copy link
Author

It's done! 😃 I removed AboutActivity.launch from onCreate() and added the following in onOptionsItemSelected():

if (id == R.id.action_about) {
            Intent intent = new Intent(this, AboutActivity.class);
            startActivity(intent);
            return true;
        }

Everything works fine now! Thank you 😃.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants