Categories
discuss

Make an expanding circle that reveals behind content on scale

So I have a question that’s been nagging me. Can you make a circle, that when expands, “deletes” the parent, but only a part (that is the width and height of the circle) and makes the content behind that parent visible? Here’s a sketch:

Can you do something like that? The closest I’ve gotten is mix-blend-mode: difference; but it only works with colours and not other various content such as text.

Answer

You can do such thing with radial-gradient within a pseudo element as a top layer then simply control background-size:

.box {
  width:200px;
  height:100px;
  background:blue;
  position:relative;
  color:#fff;
}
.box:before {
  content:"";
  position:absolute;
  top:0;
  right:0;
  left:0;
  bottom:0;
  background-image:radial-gradient(circle at center, transparent 20%,blue 22%);
  background-size:100% 100%;
  background-position:center;
  background-repeat:no-repeat;
  transition:1s;
}
.box:hover::before {
  background-size:500% 500%;
}
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vulputate dignissim leo, sed varius urna lacinia et. Vivamus volutpat turpis tellus, sit amet lobortis quam finibus non. Nunc ac sodales lectus, et dictum enim. Praesent blandit pulvinar erat, eu facilisis tortor varius id. Vivamus a pulvinar ante. 
</div>

You can also consider box-shadow and make the pseudo-element to be a circle:

.box {
  width:200px;
  height:100px;
  background:blue;
  position:relative;
  color:#fff;
  overflow:hidden;
}
.box:before {
  content:"";
  position:absolute;
  width:40px;
  height:40px;
  border-radius:50%;
  box-shadow:0 0 0 2000px blue;
  top:calc(50% - 20px);
  left:calc(50% - 20px);
  transition:1s;
}
.box:hover::before {
  width:250px;
  height:250px;
  top:calc(50% - 125px);
  left:calc(50% - 125px);
}
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vulputate dignissim leo, sed varius urna lacinia et. Vivamus volutpat turpis tellus, sit amet lobortis quam finibus non. Nunc ac sodales lectus, et dictum enim. Praesent blandit pulvinar erat, eu facilisis tortor varius id. Vivamus a pulvinar ante. 
</div>

Here is another way in case you need some transparency:

.box {
  margin-top:80px;
  margin-left:130px;
  width:40px;
  height:40px;
  border-radius:50%;
  color:#fff;
  overflow:hidden;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:1s all;
}
.box > span {
  flex-shrink:0;
  background:blue;
  width:200px;
  height:100px;
  overflow:hidden;
}
.box:hover {
  margin:0px;
  width:300px;
  height:200px;
}
body {
 margin:0;
 background:pink;
}
<div class="box">
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vulputate dignissim leo, sed varius urna lacinia et. Vivamus volutpat turpis tellus, sit amet lobortis quam finibus non. Nunc ac sodales lectus, et dictum enim. Praesent blandit pulvinar erat, eu facilisis tortor varius id. Vivamus a pulvinar ante. 
</span>
</div>

A more tricky way with only background and without extra element or pseudo element (work only with text)

.box {
  width:200px;
  height:100px;
  position:relative;
  background:
   radial-gradient(circle at center, #000 20%,transparent 22%);
  background-size:100% 100%;
  background-position:center;
  background-clip: text;
  color: transparent;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  transition:1s;
}
.box:hover {
  background-size:500% 500%;
}
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vulputate dignissim leo, sed varius urna lacinia et. Vivamus volutpat turpis tellus, sit amet lobortis quam finibus non. Nunc ac sodales lectus, et dictum enim. Praesent blandit pulvinar erat, eu facilisis tortor varius id. Vivamus a pulvinar ante. 
</div>

And let’s don’t forget the clip-path solution:

.box {
  width:200px;
  height:100px;
  position:relative;
  background:blue;
  color:#fff;
  transition:1s;
  -webkit-clip-path: circle(22% at 50% 50%);
clip-path: circle(22% at 50% 50%);
}
.box:hover {
  -webkit-clip-path: circle(80% at 50% 50%);
clip-path: circle(80% at 50% 50%);
}
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vulputate dignissim leo, sed varius urna lacinia et. Vivamus volutpat turpis tellus, sit amet lobortis quam finibus non. Nunc ac sodales lectus, et dictum enim. Praesent blandit pulvinar erat, eu facilisis tortor varius id. Vivamus a pulvinar ante. 
</div>
Categories
discuss

Using Material Button gives ClassNotFound runtime error

I am in the process of replacing the buttons in my app with Material Buttons using <com.google.android.material.button.MaterialButton in the XML file and private MaterialButton dateButton; in the Java fragment file. I studied the Code Lab “MDC-101 Android: Material Components (MDC) Basics (Java)” to see how a Material Button is used. In the gradle.build (Module:app) file I added the dependencies like in the code lab. The code lab compiles and runs fine. My app compiles fine but gives an error when inflating the fragment layout:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: nl.kl_solutions.schedulecompareforzermelo, PID: 16708
              android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.button.MaterialButton
              Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.google.android.material.button.MaterialButton
              Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.material.button.MaterialButton" on path: DexPathList[[zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/base.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_dependencies_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_resources_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_0_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_1_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_2_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_3_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_4_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_5_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_6_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_7_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_8_apk.apk", zip file "/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/nl.kl_solutions.schedulecompareforzermelo-o6fuvqQPirym08EhaTRI6Q==/lib/x86_64, /system/lib64]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)

This is a snippet from my layout file:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/primaryLightColor"
    android:paddingLeft="@dimen/rasterleftpadding"
    android:paddingRight="@dimen/rasterrightpadding" >

    <Button
        android:id="@+id/btn_previous"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="left"
        android:text="prev" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btn_week"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
         />

    <Button
        android:id="@+id/btn_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:text="next" />

</LinearLayout>

And here is a snippet from the onCreateView:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View fragmentLayout = inflater.inflate(R.layout.fragment_week_schedule, container, false);
    //get references to the buttonBar buttons.
    leftButton = fragmentLayout.findViewById(R.id.btn_previous);
    rightButton = fragmentLayout.findViewById(R.id.btn_next);
    dateButton = fragmentLayout.findViewById(R.id.btn_week);

I only changed the datebutton to a Material Button which gives me the error. The app runs fine when using an ordinary Button for the dateButton.

This is my gradle.build file:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$rootProject.supportVersion"
implementation "com.android.support:preference-v7:$rootProject.supportVersion"
implementation "com.android.support:recyclerview-v7:$rootProject.supportVersion"
implementation "com.android.support:cardview-v7:$rootProject.supportVersion"
implementation "com.android.support.constraint:constraint-layout:1.1.3"
implementation "com.android.support:design:$rootProject.supportVersion"
implementation "com.android.support:support-v4:$rootProject.supportVersion"
implementation 'com.google.code.gson:gson:2.8.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

//database components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"

// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
//QR library
implementation 'me.dm7.barcodescanner:zxing:1.9.8'

where $rootProject.supportVersion is 28.0.0-beta01. I know that rc-01 and rc02 for some libraries are available but I ran the code lab with the beta01 dependencies so decided to keep this version to minimize changes.

Anybody knows what is causing the runtime error?

Answer

As it suggest HERE you have to add a dependency in your build.gradle:

implementation 'com.google.android.material:material:1.0.0-beta01'

Or if you already use google support design library you must change your app theme to inherit from a Material Components theme

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
<!-- ... -->

If you cannot change your theme to inherit from a Material Components theme, you can inherit from a Material Components Bridge theme.

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.Bridge">
<!-- ... -->

How Reyske said:

note that it is out of beta now! So you can use implementation 'com.google.android.material:material:1.0.0'

Categories
discuss

How to solve app launch – app is stuck on white screen

I check the error log, and it shows:

08-31 13:36:18.778 13207-13207/? I/art: Late-enabling -Xcheck:jni
08-31 13:36:18.877 13207-13207/com.knowyourmeds D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
08-31 13:36:18.888 13207-13207/com.knowyourmeds D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
08-31 13:36:18.902 13207-13207/com.knowyourmeds V/FA: Cancelling job. JobID: 380685678
08-31 13:36:18.904 13207-13207/com.knowyourmeds V/FA: Registered activity lifecycle callback
08-31 13:36:18.905 13207-13207/com.knowyourmeds I/FirebaseInitProvider: FirebaseApp initialization successful
08-31 13:36:18.937 13207-13224/com.knowyourmeds V/FA: Collection enabled
08-31 13:36:18.938 13207-13224/com.knowyourmeds V/FA: App package, google app id: com.knowyourmeds, 1:694023459332:android:ffd849037d9dc14b
08-31 13:36:18.939 13207-13224/com.knowyourmeds I/FA: App measurement is starting up, version: 11910
    To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
    To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.knowyourmeds
08-31 13:36:18.939 13207-13224/com.knowyourmeds D/FA: Debug-level message logging enabled
08-31 13:36:18.956 13207-13224/com.knowyourmeds V/FA: Connecting to remote service
08-31 13:36:18.980 13207-13207/com.knowyourmeds I/CrashlyticsCore: Initializing Crashlytics 2.6.1.23
08-31 13:36:18.999 13207-13224/com.knowyourmeds V/FA: Connection attempt already in progress
08-31 13:36:19.008 13207-13207/com.knowyourmeds I/CrashlyticsInitProvider: CrashlyticsInitProvider initialization successful
08-31 13:36:19.018 13207-13207/com.knowyourmeds E/com.facebook.internal.AttributionIdentifiers: getAttributionIdentifiers should not be called from the main thread
08-31 13:36:19.025 13207-13243/com.knowyourmeds D/NetworkSecurityConfig: No Network Security Config specified, using platform default
08-31 13:36:48.923 13207-13223/com.knowyourmeds E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE

I also tried cleaning the project, restarting Android Studio and deleted the app from the device.

How should I resolve this issue?

Answer

Try below:
1. In your app level gradle, you must have used implementation “com.facebook.android:facebook-android-sdk:[4,5)”
2. Try to remove this or upgrade to the latest sdk

Categories
discuss

Is there way of optimizing below code further using java8?

I encountered below code in my project. I was wondering if it can be optimized further may be by using java 8 streams or by collection APIs in general.

private Set<Student> getFilteredSet() {
    Set<Student> unfilteredSet = getAllStudents();
    Set<Student> adminAreaSet = getAdminStudents();

    Set<String> adminAreaID = new HashSet<>();
    Set<Student> filteredSet = new HashSet<>();

    for (final Student student : adminAreaSet) {
        adminAreaID.add(student.getId());
    }
    for (final Student student : unfilteredSet) {
        if (adminAreaID.contains(student.getId())) {
            filteredSet.add(student);
        }
    }   
    return filteredSet;
}

Note: unfilteredSet and adminAreaSet hold different child types of Student

Answer

Since the question is tagged with , one way to improve readability of the code could be to transform it as :

Set<String> adminAreaID = getAdminStudents().stream()
        .map(Student::getId)
        .collect(Collectors.toSet());

return getAllStudents().stream()
        .filter(student -> adminAreaID.contains(student.getId()))
        .collect(Collectors.toSet());
Categories
discuss

xml2js in Angular 6: Can’t resolve ‘stream’ and ‘timers’

I would like to parse xml data, retrieved from the server. Unfortunately HttpClient does not support xml, only json, therefore I installed the package xml2js:

npm install xml2js --save
npm install @types/xml2js --save-dev

Then I try to use it like this:

import {Parser} from 'xml2js';

Parser.parseString(xml_str, function (err, result) {
    console.dir(result);
});

I get these two errors if I run it:

WARNING in ./node_modules/xml2js/node_modules/sax/lib/sax.js
Module not found: Error: Can't resolve 'stream' in 'C:projectsappnode_modulesxml2jsnode_modulessaxlib'

ERROR in ./node_modules/xml2js/lib/parser.js
Module not found: Error: Can't resolve 'timers' in 'C:projectsappnode_modulesxml2jslib'

I haven’t found any solutions to this problem, maybe it is an Angular6 issue only. Is there any way, to parse xml in Angular6?

Answer

You’ll have to install those dependencies. It’s unfortunately not well documented.

npm install --save stream timers
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..